Switch-2

 

In this example of JavaScript switch statement, we will pass new Date().getDay() to switch statement and if the value is 0 it will return Sunday and if value is 6 it will return "Saturday" if the values is not 0 or 6 then it will execute default test case and output as "Looking forward to the Weekend" See the code snippet:

 
 
 
<!DOCTYPE html> <html> <head> <title>Welcome to LearnKode - A code learning platform</title> </head> <body> <p id="sample"></p> <script> 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("sample").innerHTML = text; </script> </body> </html>
Output