Files
Randell Dawson 1494a50123 fix(guide): restructure curriculum guide articles (#36501)
* fix: restructure certifications guide articles
* fix: added 3 dashes line before prob expl
* fix: added 3 dashes line before hints
* fix: added 3 dashes line before solutions
2019-07-24 13:29:27 +05:30

644 B

title
title
Adding a Default Option in Switch Statements

Adding a Default Option in Switch Statements


Hints

Hint 1

Adding a default option makes sure that in case your variable doesn't match any of the options, the default will be used.


Solutions

Solution 1 (Click to Show/Hide)
function switchOfStuff(val) {
  var answer = "";

  switch (val) {
    case "a":
      answer = "apple";
      break;
    case "b":
      answer = "bird";
      break;
    case "c":
      answer = "cat";
      break;
    default:
      answer = "stuff";
  }

  return answer;
}