2
I started studying JS 3 weeks ago and am well apprenticed...
My biggest current duplicitous is that I don’t know an operator or command to identify and condition the value of the data type entered by the user, example:
var userValue = prompt("Digite um valor numérico");
if(typeof userValue == "string"){
alert("Você precisa digitar um valor numérico para prosseguir");
return false;
}
else{
alert("Ok, vamos prosseguir");
...codigo...
}
As you can see I used tried to use the typeof
to identify... in the case if string
will return false...
It turns out anything I type into prompt he interprets as string
...
There’s no point in using it either parseInt
or +
in the prompt because then he always interprets how number
the entered value...
What could I do in this case?
Thank you from now on for your attention ^^
A number can always be a string, so it doesn’t help what you’ve done. But Cvoce knows that a number has no non-numeric characters other than '.' right? This should help.
– Lucas Virgili
I appreciate your answer, Lucas! But, in a + objective way, how should it look for the user to type letters return false and type number give true?
– ropbla9