简体   繁体   中英

why i am not getting output in this code?

<!DOCTYPE html>
<html>
<head>

<title> javascript </title>
</head>
<body>

<h2>JavaScript switch</h2>

<p id="demo"></p>

<script>
let x = prompt('enter no');

switch (x) {

           case 0:
              text = "off";
              break;
           case 1:
              text = "On";
              break;
           default:
              text = "No value found";
}
document.getElementById("demo").innerHTML=text;
</script>
</body>
</html>

in the above code i want user to enter the input and then i want to display output but every time i try to do this the the only defaut=lt output comes output, why?

Use Number() to convert to a numerical value

let x = Number(prompt('enter no'));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM