JS - ifelse condition

0 votes
396 views
added Jul 6, 2018 in Javascript by LC Marshal Captain (25,790 points)
edited Jul 12, 2018 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!')
}

3 Responses

0 votes
responded Jul 6, 2018 by LC Marshal Captain (25,790 points)
edited Jul 12, 2018 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, 2018 by LC Marshal Captain (25,790 points)
edited Jul 12, 2018 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!')
}
0 votes
responded May 30, 2019 by LC Marshal Captain (25,790 points)
edited May 30, 2019 by LC Marshal
//if body has class
window.onload = function() {
  var url = window.location.pathname; 
  var activePage = url.substring(url.lastIndexOf('/') + 1);
  var element = document.getElementById(activePage);
  if(document.body.classList.contains('page-content')){
    element.classList.remove("active");
  }
  else {
    element.classList.add("active");
  }
};

 

lazacode.org - Malaysia's programming knowledge sharing platform, where everyone can share their finding as reference to others.
...