I have two variables in a script (DocumentType or Documents_Details). One or the other contains text.
I wish to see if either of them include a specific word (Passport).
I set up an IF condition to test:
`if (DocumentType.includes(“passport”) OR (documents_details.includes(“passport”)) {
console.log(“there is a passport here”);
} else {
console.log(“there is NO passport here”);
`
But get an error message:
“I-CertDoc: SyntaxError: Unexpected identifier ‘OR’. Expected ‘)’ to end an ‘if’ condition., line:153”
I tried to follow what is on this page: https://www.w3schools.com/sql/sql_and_or.asp, but it is not producing the desired result. Any help would be gratefully received.
The SQL documentation doesn’t really help much as this is Javascript that you should refer to: https://www.w3schools.com/js
The logical OR operation in JS is ||
. includes
is a method used on arrays, you might look at match
instead (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match).
Daniel,
Thank you. You are right I was looking at SQL rather than JavaScript.
Even replacing OR with || still generated an error. It was only when I realised that there was an extra “(” which caused still caused an error:
if (DocumentType.includes("passport") || *(*documents_details.includes("passport")) {
before the document_details variable…