Challenge [Adding a default option in Switch statements](http://www.freecodecamp.com/challenges/adding-a-default-option-in-switch-statements has an issue.
User Agent is: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:43.0) Gecko/20100101 Firefox/43.0
.
Statement 1 should have a semi-colon in the example similar to the line ending semi-colon for Statement 2.
Darnit, thought we fixed that one.
i think there is still some issue !
@zicmic You're welcome to open another issue with your code, but I strongly encourage you to ask for help in Help JavaScript Chat to get confirmation of the bug before you open an issue. We see many issues opened for "site bugs" where it's simply a programming error.
Thanks and Happy Coding!
It's not working for me either. It drops to default every time.
``function myTest(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";
break;
}
// Only change code above this line
return answer;
}
// Change this value to test
myTest("b");
This appears to be a code issues try changing the
switch(answer)
To
switch(val)
Candelario Daniel Eguia
University of La Verne 2016
Computer Science and Engineering in Software
On Feb 20, 2016 4:55 PM, "Susan Winters" [email protected] wrote:
It's not working for me either. It drops to default every time.
``function myTest(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";
break;
}// Only change code above this line
return answer;
}
// Change this value to test
myTest("b");—
Reply to this email directly or view it on GitHub
https://github.com/FreeCodeCamp/FreeCodeCamp/issues/6294#issuecomment-186711881
.
Was this issue ever resolved?
I am having the same issue,
whether i change switch to val or answer i still get the reference error
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);
@HarleyGreaves if you get stuck or have questions with a challenge in the future, please first ask questions to the Help Room. Happy coding!
@HarleyGreaves
Works for me, try adding CASE "a" , "b", "c" to your code and it will work
function myTest(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";
}
why it's wrong???
// Only change code above this line
return answer;
}
// Change this value to test
myTest(1);
There is no need to make so many changes to the code.
Hint what is the (val)
you are trying to match.
// Change this value to test
switchOfStuff("a");
For it to work it is necessary to assign a value to the variable answer, assigning it the argument val; Otherwise when calling the function nothing ...
function switchOfStuff(val) {
var answer = val;
// 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("c");
People keep saying use the help forum but the help forum is not viewable on my i6s phone.
the only mistake that usually all of us were doing, is that we tried to invoke the function switchOfStuff(with the wrong value). Remember: the solution:
!! switchOfStuff("b"); !! --> the case "b", or "c" or "a". (not a, b, or c,or 1, or another values.)
the correct result:
removed solution by mod
var answer = ""; (Is fine and should not be changed.)
Switch should look like this:
switch (val)
I saw that everyone, even myself, was using (answer) instead of (val). Use (val) Your code should work then.
Most helpful comment
@HarleyGreaves
Works for me, try adding CASE "a" , "b", "c" to your code and it will work