Hi guys, I am struggling with this exercise https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/golf-code. I went back to the basics and move on from here: https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/introducing-else-if-statements but I am still stuck.
My code is:
const 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 if (strokes >= par + 3) {
return "Go Home!";
}
// Only change code above this line
}
golfScore(5, 4);
And it only says the ones on top of Bogey are correct :
Passed: golfScore(4, 1) should return the string Hole-in-one!
Passed: golfScore(4, 2) should return the string Eagle
Passed: golfScore(5, 2) should return the string Eagle
Passed: golfScore(4, 3) should return the string Birdie
Passed: golfScore(4, 4) should return the string Par
Passed: golfScore(1, 1) should return the string Hole-in-one!
Passed: golfScore(5, 5) should return the string Par
Failed: golfScore(4, 5) should return the string Bogey
Failed: golfScore(4, 6) should return the string Double Bogey
Failed: golfScore(4, 7) should return the string Go Home!
Failed: golfScore(5, 9) should return the string Go Home!
Please, if someone could give me a hink on what I am failing without letting me know the answer I would really apreciatte. Kind regards,
Manuel
Edit:
The thing is, when I change the order of the code :
const 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 +3) {
return "Go Home!";
} else if (strokes >= par +2) {
return "Double Bogey";
} else if (strokes >= par +1) {
return "Bogey";
} else if (strokes = par) {
return "Par";
} else if (strokes <= par - 1) {
return "Birdie";
} else if (strokes <= par -2 ) {
return "Eagle";
}
// Only change code above this line
}
golfScore(5, 4);
It is giving me correct the ones on top of “Birdie” as I show here:
Passed: golfScore(4, 1) should return the string Hole-in-one!
Failed: golfScore(4, 2) should return the string Eagle
Failed: golfScore(5, 2) should return the string Eagle
Failed: golfScore(4, 3) should return the string Birdie
Passed: golfScore(4, 4) should return the string Par
Passed: golfScore(1, 1) should return the string Hole-in-one!
Passed: golfScore(5, 5) should return the string Par
Passed: golfScore(4, 5) should return the string Bogey
Passed: golfScore(4, 6) should return the string Double Bogey
Passed: golfScore(4, 7) should return the string Go Home!
Passed: golfScore(5, 9) should return the string Go Home!
so It just so stuck, my head is