Use switch statement with default case. - Javascript Statement

Javascript examples for Statement:Quiz

Description

Use switch statement with default case.

Demo Code

ResultView the demo in separate window

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

Related Tutorials