Query about use of OR operator

Viewing 2 reply threads
  • Author
    Posts
  • April 24, 2023 at 5:48 AM #49377

    Victor Warner
    Participant

    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.

    April 24, 2023 at 7:45 AM #49379

    Daniel Leu
    Participant

    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).

    April 24, 2023 at 10:38 AM #49380

    Victor Warner
    Participant

    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…

Viewing 2 reply threads

You must be logged in to reply to this topic.