How to make two checks in one IF ?

Ie, for example, if there is a button on the page, and the value of field 1 is 100. For example, wrote a script, but it does not work ...

if (usluga != undefined) && (url.indexOf('https://and123') +1) { alert("b") } else if (n) { alert("a"); } 

P.S. individually everything works correctly.

  • one
    wrap the condition in brackets again - BOPOH
  • 2
    What is a plus? o_O - Qwertiy
  • @Qwertiy: not clear. I do not understand why there is +1 written in the code :) - Visman
  • @Visman, to -1 turned into 0 - this is such a crappy comparison ... !== -1 . - Qwertiy
  • @Qwertiy: hmm, I meet for the first time. - Visman September

2 answers 2

I may not understand the question correctly, but this is how it works correctly:

  //Пример данных: var usluga; var url = ["https://and123", "Orange", "Apple", "Mango"]; var n = true; if ((typeof usluga !== undefined) && (url.indexOf('https://and123') +1)) { alert("b"); } else if (n) { alert("a"); } 

  • Extra brackets. Two pairs. And the question was about the syntax error due to the lack of external ones. - Qwertiy
  • Only his url is most likely a string, not an array. - Qwertiy
  • Perhaps, I indicated, only approximate data, so that the code worked. - Sever
  • Thanks more, everything works. I just did not know how to put brackets correctly. - user191380

Delete

 -----------------------v----v if (usluga != undefined) && (url.indexOf('https://and123') +1) {