JavaScript switch Statement #Part 7
In this article we are lean to switch statement in JavaScript. Simple we make a program to get input from the user and print the results as output.
Syntax
switch(val)
{
case 1:
// First alternative
break;
case 2:
// second alternative
break;
default:
// default action
}
JavaScript Code
<script>
var day=prompt(result);
var result;
switch(day){
case '1':
result="Monday";
break;
case '2':
result="Tuesday";
break;
case '3':
result="Wednesday";
break;
case '4':
result="Thursday";
break;
case '5':
result="Friday";
break;
case '6':
result="Saturday";
break;
case '7':
result="Sunday";
break;
default:
result="choose between 1 to 7 number";
}
document.write(result);
</script>
Try it Yourself...
what you think about this article ??