Javascript examples for Operator:Quiz
Use a conditional (ternary) operator to compare age
<!DOCTYPE html> <html> <body> Age: <input type="number" id="age" value="18"> <button onclick="checkAge()">Check Age</button> <p id="demo"></p> <script> function checkAge() {/*ww w.ja v a 2s . c o m*/ var age = document.getElementById("age").value; var voteable = (age < 18) ? "Too young":"Old enough"; document.getElementById("demo").innerHTML = voteable + " to vote."; } </script> </body> </html>