Showing posts with label switch statement in javascript. Show all posts
Showing posts with label switch statement in javascript. Show all posts

Sunday, December 20, 2015

Switch Statement in JavaScript

In this article I would like to share with you guys how to use and declare switch statement in JavaScript as our programming language. Switch statement is another type of conditional statement mainly use to check for conditions based on the values that is being provided by our user of our program. The advantage of using switch statement is that it is easy to understand in terms  of declaration and usage but the problem with switch statement we are not allow to use logical and relational operators that why many of conditional statements are using if - else statement instead of switch statement.

If you have some questions please send me an email at jakerpomperada@gmail.com and jakerpomperada@yahoo.com.  

My mobile number here in the Philippines is 09173084360.


Program Listing

<html>
<head>
<title> Switch Statement in JavaScript</title>
</head>
<body>
<script language = "Javascript">
var v = parseInt (prompt ("Enter a number from 0 - 9 ONLY!!!", " "));
switch (value) {
case 0:
document.write("<b>Number " + v + " is " + "ZERO in word format.");
break;
case 1:
document.write("<b>Number " + v + " is " + "ONE in word format.");
break;
case 2:
document.write("<b>Number " + v + " is " + "TWO in word format.");
break;
case 3:
document.write("<b>Number " + v + " is " + "THREE in word format.");
break;
case 4:
document.write("<b>Number " + v + " is " + "FOUR in word format.");
break;
case 5:
document.write("<b>Number " + v + " is " + "FIVE in word format.");
break;
case 6:
document.write("<b>Number " + v + " is " + "SIX in word format.");
break;
case 7:
document.write("<b>Number " + v + " is " + "SEVEN in word format.");
break;
case 8:
document.write("<b>Number " + v + " is " + "EIGHT in word format.");
break;
case 9:
document.write("<b>Number " + v + " is " + "NINE in word format.");
break;
default:
document.write("<b>Invalid Number!");
}
</script>
</body>
</html>