+ 3
Can you nest if, else if, and if statements in JavaScript?
11 odpowiedzi
+ 8
var x= 17
if( x>0){
if(x>10){
.....
}else{
if(x==9)
....
}
}else{
....
}
+ 7
Checking a value from input and write the result on the screen with javascript (else if).
Try it out:
https://code.sololearn.com/Wvobd0cYj1Em/?ref=app
Note: here is a similar code like what Wagner D'Amaral posted - just mine is work. 🙃😁
+ 3
Yes
+ 3
Yes, we can.
+ 2
Yes , we can nest as many as if statements in our program... Here, take a look..
{I have taken an example from a c++ program... but you can use it in the same way in JavaScript ;) }
if (mark >= 50) {
cout << "You passed." << endl;
if (mark == 100) {
cout <<"Perfect!" << endl;
}
}
else {
cout << "You failed." << endl;
}
+ 1
KrOW Can you give me an example? I tried to do it but I was unsuccessful.
+ 1
Ethan, try this code.
if you have question, please ask.
var x =100;
if(x < 25) {
document.write('Less than 25');
} else if (x < 50) {
document.write('Less than 50);
else if (x < 100) {
document.write('Less than 100');
else {
if (x === 100) {
document.write('Equals 100');
else {
document.write('Greater than 100');
}
}
+ 1
Ofcourse.
+ 1
Obviously yes :) . Good question though. Keep learning!
0
Yeeep
- 3
js