Add a break statement to end each case. - Javascript Statement

Javascript examples for Statement:Quiz

Description

Add a break statement to end each case.

Demo Code

ResultView the demo in separate window

<!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>

Related Tutorials