compuhelpindia.com

JavaScript Switch Statement

Compuhelpindia.com
« Previous                                                                                                                                   Next Chapter »

The switch statement is used to perform different action based on different conditions.
The JavaScript Switch Statement
Use the switch statement to select one of many blocks of code to be executed.
Eaxmple:
<!DOCTYPE html>
<html>
<body>
<script>
function compuhelp()
{
var n;
n=parseInt(prompt("Enter The Number"));
switch(n)
{
case 1:
alert("Sunday");
break;
case 2:
alert("Monday");
break;
case 3:
alert("Tuesday");
break;
case 4:
alert("Wednesday");
break;
case 5:
alert("Thursday");
break;
case 6:
alert("Friday");
break;
case 7:
alert("Saturday");
break;
default:
alert("Wrong Input");
}
}
</script>
<p>Click one of the buttons to call a function</p>
<button onclick="compuhelp()">Click Here</button>
</body>
</html> 
 

Click one of the buttons to call a function