Get your own website Result Size: 625 x 565
x
 
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Operators</h1>
<h2>The ? : Operator</h2>
<p>Input your age and click the button:</p>
<input id="age" value="18">
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
function myFunction() {
  let age = document.getElementById("age").value;
  let text = (age < 18) ? "Too young":"Old enough";
  document.getElementById("demo").innerHTML = text + " to vote.";
}
</script>
</body>
</html>