Aniket Sahrawat Aniket Sahrawat - 7 months ago 69
Javascript Question

freecodecamp Golf Code

I am trying to solve Golf Code challenge in freecodecamp and I can't really figure out what is wrong with my code
here is the direct link. Link contains the code I am trying to run, just visit the link.

My JS:

function golfScore(par, strokes) {
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";

return "Change Me";
golfScore(5, 4);


In the game of golf each hole has a par meaning the average number of strokes a golfer is expected to make in order to sink the ball in a hole to complete the play. Depending on how far above or below par your strokes are, there is a different nickname.

Your function will be passed par and strokes arguments. Return the correct string according to this table which lists the strokes in order of priority; top (highest) to bottom (lowest):

Strokes Return:

1 "Hole-in-one!"
<= par - 2 "Eagle"
par - 1 "Birdie"
par "Par"
par + 1 "Bogey"
par + 2 "Double Bogey"
>= par + 3 "Go Home!"

Thanks for help in Advance.


You're pretty much there. The only reason your solution isn't being accepted is because you are returning Go Home instead of Go Home! (note the exclamation mark at the end).