Adding a default option in Switch statements 1

Adding a default option in Switch statements 1
0.0 0

#1

Tell us what’s happening:

What am I doing wrong?

Your code so far

function switchOfStuff(val) {
  var answer = "";
  // Only change code below this line
  switch (val) {
    case "a":
  answer = "apple";
      break;
  }
   switch (val) {
     case "b":
       answer = "bird";
       break;
   }
  switch (val) {
    case "c":
      answer = "cat";
      break;
 
 default:
      answer = "stuff";
  }
      

  
  // Only change code above this line  
  return answer;  
  }

// Change this value to test
switchOfStuff("a");

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36.

Link to the challenge:


#2

Hi there,

You’re meant to use a single switch statement, with several cases.

Switches are a nifty way to handle loads of conditions without having to use way too many else if statements.

As an example:

switch(c) {
    case 1:
        answer = "one";
        break;
    case 2:
        answer = "two";
        break;
    default:
        answer = "another number";
}

Good luck and happy coding!


#3

Thank you, that worked!