Challenge Selecting from many options with Switch Statements has an issue.
User Agent is: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36
.
Please describe how to reproduce this issue, and include links to screenshots if possible.
My code:
`````` javascript
function caseInSwitch(val) {
var answer = " ";
// Only change code below this line
switch(answer) {
case 1:
console.log("alpha");
break;
case 2:
console.log("beta");
break;
case 3:
console.log("gamma");
break;
case 4:
console.log("delta");
break;
default:
}
// Only change code above this line
return answer;
}
// Change this value to test
caseInSwitch(1);
```What to value to assign to var answer=" ";
``````
@venkyafhs thanks for the issue. I'm not sure what your particular issue is but I assume it is the issue with the tests not rendering correctly.
Currently, the <code>
tags are not closed. So these:
...'message: <code>caseInSwitch(1) should have a value of \"alpha\"
need to be
...'message: <code>caseInSwitch(1)</code> should have a value of \"alpha\"
for the first four tests.
These four lines need to be changed.
Edit: I just found your note at the bottom What to value to assign to var answer
. You were supposed to set answer
to the strings you've printed to the console.
Write a switch statement which tests
val
and sets answer for the following conditions:
If you get stuck with a challenge, please ask questions to the Help Room. Happy coding!
@erictleung you rock. Just when we needed more first timers issues! :sparkles:
I will work on this from now. Is that ok ? Please let me know if there is any conflict.
Thank you.
@InsomniacSabbir Awesome!
Please, check our Guidelines for Contributing and if you need any assistance reach out to the Contributors Chat room.
Hello,
I have added the as mentioned in the previous comment. But the problem still remains. Can you please help me to find the code where the view is generated.
Thank you.
@InsomniacSabbir You need to run gulp
to view changes.
Chat with us in the Contributors Chat room.
you do not have to console.log, think about using answer as your return value. i will give you the first one as an example, your switch should be val not answer but your returning answer
switch(val) {
case 1:
answer= ("alpha");
break;
//do the the same thing for what you have left
}
// Only change code above this line
return answer;
}
this should help
function caseInSwitch(val) {
var answer = val; //here need set answer = val and your code work!)
// Only change code below this line
switch (answer) {
case 1:
answer = "alpha";
break;
case 2:
answer = "beta";
break;
case 3:
answer = "gamma";
break;
case 4:
answer = "delta";
break;
}
// Only change code above this line
return answer;
}
// Change this value to test
caseInSwitch(2);
also your switch should be switch(val) not answer
Gah! I'm stuck, and not too sure what I'm missing on this... Any pointers, would be much appreciated...
`function caseInSwitch(val) {
var answer = "";
// Only change code below this line
switch (val){
case "1": answer = ("alpha");
break;
case "2": answer = "beta";
break;
case "3": answer = "gamma";
break;
case "4": answer = "delta";
break;
}
// Only change code above this line
return answer;
}
// Change this value to test
caseInSwitch(1);`
@iameuanmackay
Please use the HelpJavaScript chat room for getting challenge related help.
Happy Coding.
function caseInSwitch(val) {
var answer = val;
// Only change code below this line
switch (answer){
case 1:
answer = "alpha";
break;
case 2:
answer = "beta";
break;
case 3:
answer = "gamma";
break;
case 4:
answer = "delta";
break;
default:
}
// Only change code above this line
return answer;
}
// Change this value to test
caseInSwitch(3);
All you need do is get the code:
@cara06 please provide all asssitance in the chat rooms.
just one thing: the default should always be there in a switch statement.
kouflor you should not use console.log. At the bottom the return statement is equal to answer (return answer;). There's a hint.
Also the in the switch you don't use (answer).
Good luck.
function caseInSwitch(val) {
var answer = val;
// Only change code below this line
switch (answer){
case 1:
answer = "alpha";
break;
case 2:
answer = "beta";
break;
case 3:
answer = "gamma";
break;
case 4:
answer = "delta";
break;
default:
}
// Only change code above this line
return answer;
}
// Change this value to test
caseInSwitch(3);
Most helpful comment
function caseInSwitch(val) {
var answer = val; //here need set answer = val and your code work!)
// Only change code below this line
switch (answer) {
case 1:
answer = "alpha";
break;
case 2:
answer = "beta";
break;
case 3:
answer = "gamma";
break;
case 4:
answer = "delta";
break;
}
// Only change code above this line
return answer;
}
// Change this value to test
caseInSwitch(2);