Javascript examples for Statement:Quiz
Use switch statement on string value
<!DOCTYPE html> <html> <body> <input id="myInput" type="text" value="CSS"> <button onclick="checkFruit()">Check Fruit</button> <p id="demo"></p> <script> function checkFruit() {/*from w w w . j av a 2s . 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 = "Really?"; } document.getElementById("demo").innerHTML = text; } </script> </body> </html>