ELSEIF condition not working with IF and ELSE in Javascript

I would like to use ELSEIF statement to set a condition in Javascript, but it is not working. Would you please tell me what is incorrect ?

IF (value==1) {
var a = 1;
} ELSEIF (value==2) {
var a = 2;
} ELSE {
var a = 0;
}
0
give a positive ratinggive a negative rating
24 Sep 2020 at 04:59 PM
Hi,

To make it work you have to replace "ELSEIF" with "ELSE IF". ELSEIF is used in PHP. In Javascript is used ELSE IF function. The code should look like:


IF (value==1) {
var a = 1;
} ELSE IF (value==2) {
var a = 2;
} ELSE {
var a = 0;
}

0
give a positive ratinggive a negative rating
27 Sep 2020 at 12:25 PM
Tim
Share on FacebookShare on TwitterShare on LinkedInSend email
x
x
Follow us on Facebook
2022 AnswerTabsTermsContact us