Javascript examples for Statement:switch
If today is neither Saturday nor Sunday, write a default message:
<html> <body> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() {/* w ww. j a v a 2 s.c o m*/ var text; switch (new Date().getDay()) { case 6: text = "Today is Saturday"; break; case 0: text = "Today is Sunday"; break; default: text = "Looking forward to the Weekend"; } document.getElementById("demo").innerHTML = text; } </script> </body> </html>