Relative Content

Tag Archive for javascriptswitch-statement

How to properly format a switch statement

Problem: It is morning if the time is 0 or more, but less than 12. If the time is 12 or more, but less than 24, it is evening. If time is any other value, greeting should always be null, whatever the language.

How does the switch statement work without the break [duplicate]

This question already has answers here: JavaScript: Understanding cases in switch (2 answers) Closed 1 hour ago. I’m using the switch statement without the breaks and it seems it defaults to the last case even if it does not meet the condition. function getLetter(s) { let letter; // Write your code here console.log(s[0]) switch (s[0]){ […]