If JavaScript starts at 0, why wouldn't Wed. be printed out? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

If JavaScript starts at 0, why wouldn't Wed. be printed out?

JavaScript question.

26th Feb 2018, 8:41 PM
Tony Love Jones
Tony Love Jones - avatar
2 Answers
+ 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)
26th Feb 2018, 8:50 PM
Tamra
Tamra - avatar
+ 3
thanks for the clarification!
27th Feb 2018, 1:32 AM
Tony Love Jones
Tony Love Jones - avatar