Here is my code
var randomNumber = Math.ceil(100 * Math.random());
switch (randomNumber) {
case (randomNumber < 20):
console.log("The number is less than 20");
break;
case (randomNumber => 20 && randomNumber < 50):
console.log("The number is between 20 and 50");
break;
case (randomNumber => 50 && randomNumber < 75):
console.log("The number is between 50 and 75");
break;
default:
console.log("The number is greater than 75");
break;
}
console.log(randomNumber);
The first part simply declares a new binding and assigns it a random integer value between 1 and 100.
The second part, the switch statement, is supposed to send a particular message, depending on the condition, the value of the randomNumber binding.
For some reason--I'm not sure why--it only executes the code corresponding to the default
keyword. And, of course, it also executes the last statement, which prints the value of the binding to the browser console.
What am I doing wrong?