I need to write a code that send an alert when user insert letters instead numbers. The should anounce that letters are not accepted and invite the user to right input again.
What i tried:
<!DOCTYPE html>
<html>
<head>
<title>Calc the age </title>
<meta charset="utf-8">
</head>
<title> Calc the age </title>
<script>
var name = prompt("Insert yout name:");
var born = parseInt(prompt("Insert your year born (with 4 numbers format):"));
var age = 2022 - born;
while (born < 1922 || born > 2021 || born === NaN) {
alert("You didn't inserted your year born correctly!")
var born = parseInt(prompt("Insert your year born (with 4 numbers format):"));
}
document.write("The year born of " + name + " is " + born + ". " + "In 2022 he'll have " + age + " years old.");
</script>
</html>