Why is this code wrong if the insturctions tell you to use strict equality ===. I have seen some solutions and they did not use strict equality. Thank you.
function caseInSwitch(val) {
var answer = "";
// Only change code below this line
switch(val) {
case val === 1:
return "alpha";
break;
switch(val)
case val === 2:
return "beta";
break;
switch(val)
case val === 3:
return "gamma";
break;
switch(val)
case val === 4;
return "delta"
break;
}
// Only change code above this line
return answer;
// Change this value to test
caseInSwitch(1);
#1. Wrong use of switch
Switch syntax works like this
switch(expr) {
case expr:
statements
break or return
case expr:
statements
breark or return
...
}
#2 You don’t need both return and break.
Return already exits from the function.
#3 Where is your closing bracelet for the function?
The case 1 answer needs to equal “alpha” in order for the code to execute. Case 2 answer needs to equal “beta” in order for the code to execute – etc. etc. etc.
Yeah, this challenge is driving me bananas as well, my code looks quite similar to yours, I’ve tried following gunhoo93’s layout/syntax but I feel like there’s some little thing that I’m not seeing.
function caseInSwitch(val) {
var answer = “”;
// Only change code below this line
switch(val) {
case 1:
“alpha”;
break;
case 2 :
“beta”;
break;
case 3 :
“gamma”;
break;
case 4 :
“delta”;
break;}
// Only change code above this line
return answer;
}
// Change this value to test
caseInSwitch(1);
syntax seems right but you are never assigning the answer
Ahhh, got it, thanks guys, I thought that was just a part of the operation like the return, this is why I ought not take extended coding breaks! Gracias!
Thank you very much for your response. Your feedback is very helpful.
Thank you for your feedback. I will try your approach.
Thank you. Your feedback is very valuable.
Thank you for sharing your code. Looking at your approach is helpful.
Did everything except add this around the code:
switch(val) {
}
thats why it didn’t pass. sigh