+ 1

Why is this not working?

Whenever I put 5 and 10 as the two numbers (others too) it will give an incorrect output. Also, when the two numbers are equal it will say NaN https://code.sololearn.com/W8mNcns0Kc1v/?ref=app

22nd Nov 2018, 3:42 AM
Yosharu
Yosharu - avatar
8 Respuestas
+ 4
Oh wait. Wait. Wait. I got the problem. Your numbers are not numbers (as in integers), they are strings!
22nd Nov 2018, 4:20 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 3
When numbers are inputted the program works fine. What you have handled wrongly is the no input case. If (num1)||(num2==NaN) is what your 3rd condition does. You need to do: if (num1==NaN||num2==NaN)
22nd Nov 2018, 4:14 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 3
Jack Rehfeldt Look at my edited answer
22nd Nov 2018, 4:25 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 2
I remember one neat "hacks" which is simply, add a + Edit: var prompt1 = +prompt("Hey"); var prompt2 = +prompt("There"); Like that
22nd Nov 2018, 4:23 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 1
⏩ Prometheus ⏪ try putting 5 in first then 10. it says 10 is smaller
22nd Nov 2018, 4:19 AM
Yosharu
Yosharu - avatar
+ 1
⏩ Prometheus ⏪ how would i turn them into integers? would i do it like: if(int(prompt1) < int(prompt2){} or?
22nd Nov 2018, 4:22 AM
Yosharu
Yosharu - avatar
+ 1
⏩ Prometheus ⏪ im confused? what?
22nd Nov 2018, 4:24 AM
Yosharu
Yosharu - avatar
+ 1
⏩ Prometheus ⏪ Works! Thank you for your help!
22nd Nov 2018, 4:33 AM
Yosharu
Yosharu - avatar