+ 2
If JavaScript starts at 0, why wouldn't Wed. be printed out?
JavaScript question.
2 Antworten
+ 10
I'm assuming you're referring to this example? If not, please post the code you're referring to: https://www.sololearn.com/learn/JavaScript/1139/
You're confusing array indexes (which start counting at 0) with switch cases.
A switch case checks if a variable equals an exact values. So, if day were 2, the case for 2 would run, and "Tuesday" would be printed. To print Wednesday, day would have to equal 3.
In other words,
case 2:
is the same as
if (day === 2)
+ 3
thanks for the clarification!