Hi, I am trying to do the golf code challenge. When I do it with the if/else statements the code is working properly. But when I try to do it with the switch statement it is not working. I would like some help to know what is wrong with my switch statement.
Here is my if/else statement which is working perfectly
function golfScore(par, strokes) {
// Only change code below this line
if (strokes==1) {
return "Hole-in-one!";
} else if (strokes<=par-2) {
return "Eagle";
} else if (strokes==par-1) {
return "Birdie";
} else if (strokes==par) {
return "Par";
} else if (strokes==par+1) {
return "Bogey";
} else if (strokes==par+2) {
return "Double Bogey";
} else if (strokes>=par+3) {
return "Go Home!";
}
// Only change code above this line
}
// Change these values to test
golfScore(5, 4);
Here is my Switch statement which ain’t working for some values while testing.
function golfScore(par, strokes) {
// Only change code below this line
var result=" ";
switch (strokes) {
case 1:
result="Hole-in-one!";
break;
case (strokes<=par-2):
result="Eagle";
break;
case par-1:
result="Birdie";
break;
case par:
result="Par";
break;
case par+1:
result="Bogey";
break;
case par+2:
result="Double Bogey";
break;
case (strokes>=par+3):
result="Go Home!";
break;
}
return result;
// Only change code above this line
}
// Change these values to test
golfScore(5, 4);
Your browser information:
Link to the challenge: