<!DOCTYPE html>
<html>
<head>
<title>abcd</title>
</head>
<body>
<p id="demo"></p>
<button onclick="vote()">click</button>
<script>
function vote(){
var age,voteable;
age = Number(document.getElementById("age").value);
if (age > 120){
voteable = "not alive";
}
else{
voteable = ( age < 18) ? "Too young" : "Old enough";
}
document.getElementById('demo').innerHTML = voteable;
}
</script>
<input id="age" value="age"/>
</body>
Here, I have only two conditions. If and else.I want to add another condition, if the input isn't a number.How do I do that?
Aucun commentaire:
Enregistrer un commentaire