A
A
A person from Kazakhstan2019-04-24 16:32:05
JavaScript
A person from Kazakhstan, 2019-04-24 16:32:05

Where is the error in the switch case?

I downloaded a new (maybe not new) course from Udemy and I do it exactly as in the lecture, but either an error falls out or I don’t understand what it is.
Here is js:

let num = 50;

switch (num) {
    case num > 60:
         console.log("Нет, переменная меньше 60");
         break;
    case num < 40:
         console.log("Нет, переменная больше 40");
         break;
    case num == 50:
         console.log("Да, переменная ровна 50");
         break;
}

This is what makes JavaScript (ES6) code snippets not work
[Deprecation] Element.createShadowRoot is deprecated and will be removed in M73, around March 2019. Please use Element.attachShadow instead. See https://www.chromestatus.com/features/4507242028072960 for more details.
createShadowTree @ include.preload.js:411
ElemHide @ include.preload.js:384
(anonymous) @ include.preload.js:512
[Violation] '2P_181d5151-666a-4b23-9dd3-0fe5446b5451' handler took 242ms

How to deal with it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Z
zendor, 2019-04-24
@LenovoId

The switch uses the strict === comparison, change the condition to switch(true) as the result of your comparisons will be true/false.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question