+ 2

Why this code return Wednesday

<!DOCTYPE html> <html> <body> <p id="demo"></p> <script> var day; switch (new Date().getDay()) { case 0: day = "Sunday"; break; case 1: day = "Monday"; break; case 2: day = "Tuesday"; break; case 3: day = "Wednesday"; break; case 4: day = "Thursday"; break; case 5: day = "Friday"; break; case 6: day = "Saturday"; } document.getElementById("demo").innerHTML = "Today is " + day; </script> </body> </html>

28th Dec 2016, 10:53 AM
Wilson Bol
Wilson Bol - avatar
2 Respostas
+ 2
It is okay. The Date().getDay() returns the calculated number of day in the week (Sunday is 0, Monday is 1, Thursday 2, Wednesday 3)...
28th Dec 2016, 12:49 PM
Petr Hatina
Petr Hatina - avatar
0
Sorry Tuesday is 2
28th Dec 2016, 12:49 PM
Petr Hatina
Petr Hatina - avatar