+ 6

Can we use multiple else if

var course = prompt ("Enter course number"); if (course == 1) { document.write("<h1>HTML Tutorial</h1>"); } else if (course == 2) { document.write("<h1>CSS Tutorial</h1>"); } else if (course == 3) { document.write("<h1>JavaScript Tutorial</h1>"); } else {document.write ("No such course available"); } Is this valid?

16th Jun 2018, 7:09 AM
Manoj
Manoj - avatar
19 Antworten
+ 6
Hello, Manoj! That's right, this is a valid action Please see the lesson from SoloLearn to understand the whole concept of "conditions" https://www.sololearn.com/learn/JavaScript/1138/?ref=app
16th Jun 2018, 7:13 AM
Alexander Sokolov
Alexander Sokolov - avatar
+ 9
You can use infinite number of: - if statements - else if statements Else statements 'cannot' be used infinitely. Only ONE else statement are allowed for ONE if statement.
16th Jun 2018, 11:01 AM
Muhd Khairul Amirin
Muhd Khairul Amirin - avatar
+ 6
Yes this is valid. You can use also instead of if....else if, switch case construction.
16th Jun 2018, 7:25 AM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
+ 6
thats true... 99,99% you are right...
16th Jun 2018, 11:07 PM
Jingga Sona
Jingga Sona - avatar
+ 5
Yes you can use as many else-if's as you want
16th Jun 2018, 4:08 PM
Mitali
Mitali - avatar
+ 4
Yes, it is ok
16th Jun 2018, 7:13 AM
Ederson Conegero
Ederson Conegero - avatar
+ 4
yes it is indeed valid
16th Jun 2018, 9:57 AM
Diego de Kruif
Diego de Kruif - avatar
+ 4
Yes,why not? This approach can be very helpful in checking many conditions at a time.
17th Jun 2018, 12:39 PM
Sujal Kumar
Sujal Kumar - avatar
+ 3
yes it is ok
16th Jun 2018, 11:48 PM
Asim Maredia
+ 1
This is ok but using switch will make it quiet easy
16th Jun 2018, 4:42 PM
Divesh Hariani
Divesh Hariani - avatar
+ 1
yes you can use only one if and else statement but as many as you want else if statements in your code
16th Jun 2018, 6:29 PM
Toons Craze
Toons Craze - avatar
+ 1
yes ,we can do bro....
17th Jun 2018, 12:13 PM
Rahul kumar
+ 1
If else if makes code looks complex u can use switch case instead
17th Jun 2018, 12:22 PM
ᴋᵘⁿᵃˡ
ᴋᵘⁿᵃˡ - avatar
+ 1
you can use multiple times if ..else if statement.. that's called nested loop
17th Jun 2018, 6:03 PM
NEHA CHHATRIA
NEHA CHHATRIA - avatar
+ 1
Yes.You can use,but you can use switch better it.
17th Jun 2018, 10:43 PM
MahdiRahim-zadeh
0
ok thanks sir
25th Jun 2018, 7:47 PM
NEHA CHHATRIA
NEHA CHHATRIA - avatar
0
yeah
29th Sep 2019, 7:03 AM
Anupama
Anupama - avatar
0
Yes you can use as many If Else statements as you wish.
13th Sep 2020, 9:42 PM
Mohamed Muck Kamara
Mohamed Muck Kamara - avatar
- 2
yes
12th Jul 2018, 7:10 PM
Rahul kumar