Javascript examples for Statement:Quiz
Use switch statement with default case.
<!DOCTYPE html> <html> <body> <input id="myInput" type="text" value="Tutti Frutti"> <button onclick="checkFruit()">Check Fruit</button> <p id="demo"></p> <script> function checkFruit() {/* w w w .ja va2 s . c o m*/ var text; var myArray = document.getElementById("myInput").value; switch(myArray) { case "Javascript": text = "good!"; break; case "HTML": text = "OK"; break; case "CSS": text = "Yes"; break; default: text = "Sure"; } document.getElementById("demo").innerHTML = text; } </script> </body> </html>