ConditionalOperator-1

 

Conditional Operator ? will return the first value if condition is true else second value.

 
 
 
<!DOCTYPE html> <html> <head> <title>Welcome to LearnKode - A code learning platform</title> </head> <body> <input ype="text" id="age"/> <button onclick="voteableAge()">Check eligible for voting</button> <p id="sample"></p> <script> function voteableAge() { var age, voteable; age = document.getElementById("age").value; voteable = (age < 18) ? "Too young":"Old enough"; document.getElementById("sample").innerHTML = voteable + " to vote."; } </script> </body> </html>
Output