Continuing the discussion from freeCodeCamp Challenge Guide: Adding a default option in Switch statements:
function switchOfStuff(val) {
var answer = "";
// Only change code below this line
switch (answer) {case 'a': answer = 'apple';
break;
case 'b': answer = 'bird';
break;
case 'c': answer = 'cat';
break;
default: answer ='stuff';}
// Only change code above this line
return answer;
}
// Change this value to test
switchOfStuff(a);
I meant to say this is lesson 184!
Here is the copy of a correct answer (posted on the above link):
Function switchOfStuff(val) {
var answer = "";
// Only change code below this line
switch (val){
case 'a':
answer = "apple";
break;
case 'b':
answer = "bird";
break;
case 'c':
answer = "cat";
break;
default:
answer = "stuff";
}
// Only change code above this line
return answer;
}
// Change this value to test
switchOfStuff(1);
I’m moving on, but I still was wondering what I did wrong in terms of formatting in my first post. Please let me know if you have a chance!
The challenges aren’t numbered. Those are your brownie points.
<code>
function switchOfStuff(val) {
var answer = "";
// Only change code below this line
switch (val){
case 'a':
answer = ("apple");
break;
case 'b':
answer = ("bird");
break;
case 'c':
answer = ("cat");
break;
case 'd':
answer = ("stuff");
break;
case 4:
answer = ("stuff");
break;
default:
answer = ("default");
}
// Only change code above this line
return answer;
}
// Change this value to test
switchOfStuff(1);
</code>
I found that the number **4**
broke my code because it was surrounded by quotes. removed the quotes and tests pass