Try it
Javascript
Jquery
Angular
Learn Angular
Learn Javascript
Learn Bootstrap
Learn jQuery
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
×
Save This try
Title
Description
<p>Conditional Operator <code>?</code> will return the first value if condition is true else second value.</p>