Switch Case in javascript.

Switch Case:

Switch case statement is used to select one of many blocks of code to be executed.

Syntax:

Switch(expression) { case 'condition': Block statement(s); break; case 'condition2': Block statement(s); break; case 'condition3': Block statement(s); break; ..................... ..................... case 'condition n': Block statement(s); break; default: Block statement(s); break; }

Example:

Write a program in javascript to display message depending on which day of the week it is using switch case.

<!--DOCTYPE html--> <html> <head> <title>switch case</title> <script type="text/javascript"> var date=new Date(); getDay=date.getDay(); switch(getDay) { case 1: document.write("javascript"); break; case 2: document.write("ACII"); break; case 3: document.write("PYTHON"); break; case 4: document.write("JAVA"); break; case 5: document.write("PRACTICAL"); break; default: document.write("REST tODAY"); break; } </script> </head> <body> </body> </html>

output:

PRACTICAL

Comments

Popular posts from this blog

Introduction to Python.

Decision Making Statement.