Javascript examples for Statement:Quiz
Add a break statement to end each case.
<!DOCTYPE html> <html> <body> <input id="myInput" type="text" value="HTML"> <button onclick="checkFruit()">Check Fruit</button> <p id="demo"></p> <script> function checkFruit() {/*from w w w. ja v a 2 s. c om*/ var text; var myArray = document.getElementById("myInput").value; switch(myArray) { case "Javascript": text = "Good"; break; case "HTML": text = "Sure"; break; case "CSS": text = "OK"; break; default: text = "Yes"; } document.getElementById("demo").innerHTML = text; } </script> </body> </html>