Hello,
Need help with my code. Do not understand why it does not work properly.
Description:
Create a web page with a linked external script that takes as input the user age. if the age is less than 18 the web page should display "You are too young to vote" Otherwise the web page should proceed by asking if the person did register to vote or not using a prompt. If No the page should display:" You need to register before you can vote" if yes the program display: " You can vote"
Use descriptive names of variables, appropriate primary and secondary conditions ( if/else), and display correctly the outputs on the webpage based on the condition.
Code:
<head>
<title> Voting! </title>
<script type="text/javascript">
var age = prompt("Please enter your age");
if(age < 18){
document.write("You are too young to vote!");
}
else if (age >=18){
alert("You are eligible to vote!");
}
var answare = prompt("Did you register to vote?");
if (answare == 'yes'){
document.write("You can vote!");}
else
{document.write("You need to register before you can vote");
}
</script>
</head>
<body>
</body>
</html>
Need help with my code. Do not understand why it does not work properly.
Description:
Create a web page with a linked external script that takes as input the user age. if the age is less than 18 the web page should display "You are too young to vote" Otherwise the web page should proceed by asking if the person did register to vote or not using a prompt. If No the page should display:" You need to register before you can vote" if yes the program display: " You can vote"
Use descriptive names of variables, appropriate primary and secondary conditions ( if/else), and display correctly the outputs on the webpage based on the condition.
Code:
<head>
<title> Voting! </title>
<script type="text/javascript">
var age = prompt("Please enter your age");
if(age < 18){
document.write("You are too young to vote!");
}
else if (age >=18){
alert("You are eligible to vote!");
}
var answare = prompt("Did you register to vote?");
if (answare == 'yes'){
document.write("You can vote!");}
else
{document.write("You need to register before you can vote");
}
</script>
</head>
<body>
</body>
</html>