In this tutorial we are writing a JS Program to Check Eligibility for voting.
To check that a person is eligible for voting or not, we need to check whether person’s age is greater than or equal to 18. For this we are reading age in a variable a and checking the condition a>=18, if the condition is true, “person will be eligible for voting” else not.
Program Source Code : JS program to check eligibility for voting
write a program to check if a candidate is eligible for voting or not. (hint check age)
JavaScript:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> <input type="text" id="age" placeholder="enter age for vote"><br> <button id="btn">Submit Age</button> <script> document.querySelector("#btn").onclick=function(){ if(document.querySelector("#age").value >=18) alert("Eligible for Voting! ") else alert("Not Eligible for Voting! ") } </script> </body> </html> |