12.5 Programming Activity
Programming Activity (20 mins)
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Eligibility Checker</title> </head> <body> <h1>Check the Console for Eligibility Results</h1> <script> // Prompt the user to enter their age let age = prompt("Please enter your age:"); age = parseInt(age); // 1. If-Else Statement: Check voting eligibility if (age >= 18) { console.log("You are eligible to vote."); } else { console.log("You are not eligible to vote."); } // 2. Switch Statement: Check other age-based criteria switch (true) { case (age >= 21): console.log("You are eligible to drink alcohol."); // Fall through to check driving eligibility case (age >= 16): console.log("You are eligible to drive."); break; case (age < 16): console.log("You are not old enough to drive."); break; default: console.log("Invalid age entered."); } </script> </body> </html>
Challenge: show the result at <div id="showResult" ></div>
Student Activity (20 mins):
Last updated