+ 1

Why is my switch only displaying the default loop? Made a BMI calculator

https://code.sololearn.com/W9G91Tav0f62/?ref=app This is the code. Why is the BMI calculator only displaying the default statement no matter the value? Units used are kg and cm

20th Apr 2017, 2:41 AM
AceDev
4 odpowiedzi
+ 6
With the "switch/case" statement, you only can test equality of differents values: switch (imc) { case 5: document.write('imc is 5'); case 15: document.write('imc is 15'); case 25: document.write('imc is 25'); } ... by putting conditions after the 'case' keyword, you are comparing the 'imc' value to the result of the condition: "case xxx: /*do something*/" is equivalent to "if (imc /*switch tested variable*/ == xxx { /*do something*/ }" So, while imc is different from true or false, only the default case run ^^
20th Apr 2017, 3:04 AM
visph
visph - avatar
+ 6
However, isn't it strange to user input in french ( "ton poids", "ta taille"), and output in english ;P ?
20th Apr 2017, 3:10 AM
visph
visph - avatar
0
Thanks a lot! Rewrote it with else if and it works perfectly
20th Apr 2017, 3:08 AM
AceDev
0
I'm weird, sorry! Thanks again :)
20th Apr 2017, 3:15 AM
AceDev