JS Interaction - prompt

0 votes
266 views
added Jul 6, 2018 in Javascript by LC Marshal Captain (25,790 points)
edited Jul 13, 2018 by LC Marshal
//declare variable for name on prompt modal, and output the name
let yourName = prompt('what your name?');
  alert(`your name is ${yourName}`);

1 Response

0 votes
responded Jul 10, 2018 by LC Marshal Captain (25,790 points)
edited Jul 13, 2018 by LC Marshal
//Add plus on the prompt e.g '+prompt' to convert the input string into number
let emilie = +prompt('give the number', '');

switch(emilie) {
  case 0 :
    alert(0);
    break;

  case 1 :
    alert(1);
    break;
    
  case 2 :
  case 3 :
    alert('2, 3');
    break;
}
lazacode.org - Malaysia's programming knowledge sharing platform, where everyone can share their finding as reference to others.
...