Javascript examples for Operator:Quiz
Use a conditional (ternary) operator to compare string values
<!DOCTYPE html> <html> <body> First Name: <input type="text" id="fname" value="TOM"> <button onclick="checkName()">Check Name</button> <p id="demo"></p> <script> function checkName() {//from w w w. java2 s . c om var firstName = document.getElementById("fname").value; var result = (firstName === "TOM") ? "Hello TOM!":"You're not TOM!"; document.getElementById("demo").innerHTML = result; } </script> </body> </html>