Are you first timer at lazacode.org? Why not join us and start exchange your programming knowledge with everyone. Register today!

JS - ifelse condition

0 votes
11 views
added Jul 6 in Javascript by LC Marshal Lieutenant (14,570 points)
edited Jul 12 by LC Marshal
let jsName = prompt('What is the “official” name of JavaScript?', '');
if(jsName == 'ECMAScript') {
    alert('Right!')
} else if (jsName == '') {
    alert('please answer something')
}
else {
    alert('Didn’t know? ECMAScript!')
}

2 Responses

0 votes
responded Jul 6 by LC Marshal Lieutenant (14,570 points)
edited Jul 12 by LC Marshal
//example 2
let test = prompt('Give me your lucky number', 0)
if(test > 0) {
    alert(1 + ' ' + 'and above')
} else if (test < 0) {
    alert(-1 + ' ' + 'and lower')
} else if (test == 0) {
    alert(0)
}
0 votes
responded Jul 10 by LC Marshal Lieutenant (14,570 points)
edited Jul 12 by LC Marshal
let browser = prompt('What your preferred browser?', '');
if(browser === 'Chrome' || browser === 'chrome') {
  console.log("You've got the Chrome!")
} else if(browser === 'edge' || browser === 'firefox' || browser === 'safari' || browser === 'opera') {
  console.log('These browsers are supported too')
} else {
  console.log('Well, hope the page looks ok to you!')
}
lazacode.org - Malaysia's programming knowledge sharing platform, where everyone can share their finding as reference to others.
...