In client script, how can we write if else statements with syntax.

Venu24
Kilo Contributor

when I am trying to declare else, then it's showing an error unexpeced token else. How could I resolve it.

5 REPLIES 5

Prasad Pagar
Mega Sage

Hi,

Its same way you use everywhere else

if(condition){

}else if(condition)

{

}else if(condition)

Please share your current code to understand where is the error

Thank you
Prasad

Anurag Tripathi
Mega Patron
Mega Patron

Can you show script?

There is nothing out of the ordinary here but simple Javascript syntax.

-Anurag

Harish27
Kilo Guru

Post your code here so that we can see what has gone wrong. I think you might have added extra semi colon before else. 

Syntax: 

if (condition1) {
  //  block of code to be executed if condition1 is true
} else if (condition2) {
  //  block of code to be executed if the condition1 is false and condition2 is true
} else {
  //  block of code to be executed if the condition1 is false and condition2 is false
}

 

Venu24
Kilo Contributor

Thank you very much for helping me in clarifying the query.