# Basic JavaScript: Golf Code Help

Basic JavaScript: Golf Code Help
0

#1

Hello I’m stuck on the Golf Code part of this challenge. I had the first half down put after I get done with the par I got stuck. I feel like I’m getting confused by the golf concept as well here. Here is my 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 (par >= 1 && strokes === 1 ){
return names[0];
} else if(par >= 2 && strokes === 2 ) {
return names[1];
} else if (par >= 3 && strokes === 3){
return names [2];
} else if (par >= 4 && strokes >= 4){
return names[3];
} else if (par >= 4 && strokes  ){
return names[4];
} else if (par >= 4  )

return "Change Me";
// Only change code above this line
}

// Change these values to test
golfScore(4, 5);
``````

#2

In golf, each hole is given a number of strokes it would take most good players to get the ball in the hole, this is called the holes’ `par` - so for example, the longer holes in golf are a par 5, that means if you get the ball in the hole in 5 shots, you got a par on that hole - if you made it in 4 shots (1 less than par), you got a birdie - 3 shots (2 less than par) = eagle - and going the other direction, if you made it in 6 shots (1 more than par), it’s a bogey, 7 = double bogey… so the label given to the score for the hole is the deviation from par, if the hole was a par 4, then finishing it in 3 shots would be a birdie - so what you want to do is make your tests check how far away from par the strokes are, maybe something like…
`if(par + 1 === strokes ) { return "bogey" }` — hope that helps

#3

Thanks I think this helps!