0

when I receive user's age, but I don't change it to number, I can understand if my client's age is 18 or not...

var isAge = prompt("How old are you?");
alert(typeof isAge) //string
if (isAge >= 18) {
  alert("you can enter the site")
} else
  alert("you cant enter the site")
//it knows if the str in below 18 or not
depperm
  • 10,606
  • 4
  • 43
  • 67
AliDa
  • 1
  • What exactly do you want to do? Not convert the input to string and then verify if the input given is a number that's above or below 18? – tomerpacific Aug 25 '23 at 15:42
  • Do you need to use `parseInt()`? – mykaf Aug 25 '23 at 15:42
  • Maybe reading about type coercion will help you here. https://developer.mozilla.org/en-US/docs/Glossary/Type_coercion – Anton Podolsky Aug 25 '23 at 15:53
  • There's general reasoning [here](https://stackoverflow.com/questions/14533046/why-doesnt-javascript-have-strict-greater-less-than-comparison-operators). But the short answer is that's just how JS works. – Andy Aug 25 '23 at 15:55

0 Answers0