I wrote a function in Javascript that determines the eligibility to vote, greater than 18 eligible, if not, not eligible to vote. when I tried to call the function using the button Verify in HTML it was not working. I tried to display the result as a pop-up window. please look at my code and see what I am doing wrong.
The code is as follows:
<html>
<head><title>Java script</title>
</head>
<script>
function age()
{
if(document.getElementById("age")>=18)
{
window.alert("ELIGIBLE FOR VOTE!!");
}
else
{
window.alert("YOU ARE NOT ELIGIBLE FOR VOTING");
}
</script>
<body>
<h1>Enter your age:<input type="text" id="age"><br></h1>
<button type="button" onclick="javascript:age()">VERIFY</button><br>
</body>
</html>
enter image description here This is the output I got. I could not display the pop-up window