One, why does golf code expect a ; after my else and before my {?
and 2, why is in not passing with either of the following sets of code?
var names = ["Hole-in-one!", "Eagle", "Birdie", "Par", "Bogey", "Double Bogey", "Go Home!"];
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 (strokes >= par + 3) {
"Go Home!";
}
// Only change code above this line
}
golfScore(4, 1);
which gives:
SyntaxError: unknown: Unexpected token, expected ";" (16:28)
14 | }else if(strokes == par + 2){
15 | return "Double Bogey";
> 16 | } else (strokes >= par + 3) {
| ^
17 | "Go Home!";
18 | }
19 |
or, with the ; added where it reccomends:
var names = ["Hole-in-one!", "Eagle", "Birdie", "Par", "Bogey", "Double Bogey", "Go Home!"];
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 (strokes >= par + 3); {
"Go Home!";
}
// Only change code above this line
}
golfScore(4, 1);
which gives
// running tests
golfScore(4, 7) should return "Go Home!"
golfScore(5, 9) should return "Go Home!"
// tests completed
I can copy and paste a nearly identical solution and it works, but I’m not moving on until I know why this doesn’t
The solution from the hints that worked:
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 {
return "Go Home!";
}
what’s the functional difference and why did it tell me to add a ; after my else statement?