so this code does of course work:
<!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>
but without the break;
statement it doesnt:
<!DOCTYPE html>
<html>
<body>
<p id="demo"></p>
<script>
var day;
switch (new Date().getDay()) {
case 0:
day = "Sunday";
case 1:
day = "Monday";
case 2:
day = "Tuesday";
case 3:
day = "Wednesday";
case 4:
day = "Thursday";
case 5:
day = "Friday";
case 6:
day = "Saturday";
}
document.getElementById("demo").innerHTML = "Today is " + day;
</script>
</body>
</html>
I wonder why it will display "saturday" if i omit the break statement even saturday isnt ever the case since today is tuesday. Do you know why it will go in case 6 and output saturday instead of nothing when the break statement is omitted? thanks for you help.