0

# How can I check which number is greater,lesser using two variables in JavaScript?

I have to do it using switch/case. It is for a course I am taking. var NumOne = 10, NumTwo = 13; switch(NumOne,NumTwo) { case(NumTwo < NumOne): alert(numTwo + " is not less than " + NumOne); break; case(NumTwo > NumOne): alert(numTwo + " is greater than " + NumOne); break; } This is what I have come up with but I would like to have a working example... Can anyone help?

10th Apr 2017, 1:28 PM
Ivaylo Dimitrov
+ 23
10th Apr 2017, 1:29 PM
Valen.H. ~
+ 12
switch (NumOne > NumTwo) { case true: //NumOne is greater; break; case false: //NumTwo is greater; break; default: //equal; } ?
10th Apr 2017, 1:41 PM
The Coding Sloth
+ 2
Thanks for the replies :) I also got it running using: var var1 = 10, var2 = 13; var x = var1 > var2, y = var1 < var2; switch (x, y) { case x: alert(var1 + " is bigger than " + var2); break; case y: alert(var1 + " is less than " + var2); break; }
10th Apr 2017, 1:54 PM
Ivaylo Dimitrov
+ 1
What about if statement? I think its easier and better way of doing that or first guy's answer to your question
10th Apr 2017, 2:25 PM
Luka Kldiashvili
+ 1
o
10th Apr 2017, 3:22 PM
FoXcodeZ
0
Yes with "if" and with ValentinHacker's code it will be easier, but my assignment was to do it with switch/case
10th Apr 2017, 5:37 PM
Ivaylo Dimitrov