0

In this code, case 2 & case 4 (switch statement) doesn't working, help me fix errors.

<!DOCTYPE html> <html> <head> <script language="javascript" type="text/javascript"> var m=prompt("month number"); switch(m) { //case1 case "1"||"2"||"3": document.write("Winter"); break; //case2 case "4"||"5"||"6": document.write("Summer"); break; //case3 case "7"||"8"||"9": document.write("Spring"); break; //case4 case "10"||"11"||"12": document.write("Autumn"); break; default: document.write("something went wrong"); } </script> </head> </html>

29th Feb 2020, 12:55 PM
Krishna Pratap
Krishna Pratap - avatar
2 Respuestas
+ 4
This is wrong syntax of switch-case statement. Multiple case values can be combined like this : case "1": case "2": case "3": docunent.write("Winter"); break; Try this for entire code. Have a moment to look at JS documentation. Don't code by guessing syntax. 👍 https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/switch
29th Feb 2020, 1:36 PM
🇮🇳Omkar🕉
🇮🇳Omkar🕉 - avatar
0
Thanks! it is working now.,😃
1st Mar 2020, 8:49 PM
Krishna Pratap
Krishna Pratap - avatar