I am trying to make a script in which a prompt window will pop up asking a question, and based on what the answer in it is, an alert box will pop up saying that the answer is valid or invalid. In my code, my prompt box works, but my alert box didn't. Can someone help me solve this problem please? Thank you so so much!!
<!DOCTYPE HTML>
<html>
<script type="text/javascript">
var City=prompt("Enter your city", "City");
function checkName(){
var validLetters=/^[a-z]+$/i;
if(validLetters.test(City))
alert("Your input is accepted!");
else
alert("Your input is invalid!");
}
</script>
Aucun commentaire:
Enregistrer un commentaire