Click here to Skip to main content
15,889,116 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
JavaScript
var ask= prompt("Please insert number or string);
alert(typeof ask);

i am using above code but it return me only string not number (if i type Number).
what to do if i use below logic then this will also fail becuase now it will return only number
JavaScript
var ask= parseInt(prompt("Please insert number or string));
alert(typeof ask);
Posted

1 solution

dialog boxes in JavaScript always return string. Use isNaN() to determine, like this:
XML
<!DOCTYPE html>
<html>
<head>
<script>
var ask= prompt("Please insert number or string");
if (isNaN(ask)){
    alert("You enter a string");
} else {
    alert("You enter a Number");
}
</script>
</head>
<body>
</body>
</html>
 
Share this answer
 
Comments
Schatak 1-Nov-14 6:08am    
Correct :)
Muhamad Faizan Khan 1-Nov-14 6:14am    
thanks
Peter Leow 1-Nov-14 6:26am    
You are welcome.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900