Why is my typeof detection code not working? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why is my typeof detection code not working?

https://code.sololearn.com/Wlzn739ZDpQ3/?ref=app

20th Apr 2017, 4:59 PM
AceDev
2 Answers
+ 5
Write your if condition like this typeof(num)== 'number'
20th Apr 2017, 5:02 PM
Ashwani Kumar
Ashwani Kumar - avatar
+ 4
try this code <!DOCTYPE html> <html> <head> <title>Page Title</title> </head> <body> <script>var num="randomtedt"; if (typeof(num) == "number"){ alert("c un nombre") ; } else { alert("pas un nombre") ; }</script> </body> </html> differences are == instead of = "number" instead of number == compare opertation number is a string not a variable
20th Apr 2017, 5:09 PM
Oliver