# Help with Golf Challenge

why doesnt this work

``````      if(strokes==2){ return "Eagle";
} else if(strokes==1){ return "Hole-in-one!";
} else if(par==strokes){ return "par";
} else if(par==strokes-1){ return "Birdie";
} else if(par==strokes+1){ return "Bogey";
} else if(par==strokes+2){ return "Double Bogey";
} else if(par>strokes+2){ return "Go Home!";
}
``````

Iâ€™ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the â€śpreformatted textâ€ť tool in the editor (`</>`) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (â€™).

are you sure this is the condition? try looking at the table again

Also, you have your conditions a little bit backwards.

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!â€ť

These conditions on the left are values that `strokes` must match.

It could be i didnâ€™t understand golf. I thought par 5 strokes 2 and par 4 strokes 2 are both Eagle.
`golfScore(4, 2)` should return â€śEagleâ€ť
`golfScore(5, 2)` should return â€śEagleâ€ť

anyways the errors it was giving me was on stuff that we agree should have worked

What this says, in words is â€śif par is one less than strokes, then you have a Birdieâ€ť.

That does not match the table:

the table happens to contradict the tests

i switched it to `else if(strokes==par-1){ return "Birdie";`

// running tests

``````golfScore(4, 4)
``````

should return â€śParâ€ť

``````golfScore(5, 5)
``````

should return â€śParâ€ť

``````golfScore(4, 5)
``````

should return â€śBogeyâ€ť

``````golfScore(4, 6)
``````

should return â€śDouble Bogeyâ€ť

``````golfScore(4, 7)
``````

should return â€śGo Home!â€ť

``````golfScore(5, 9)
``````

should return â€śGo Home!â€ť // tests completed

Did you make that same change for all conditions? What is your current code?

``````      if(strokes==2){ return "Eagle";
} else if(strokes==1){ return "Hole-in-one!";
} else if(par==strokes){ return "par";
} else if(strokes==par-1){ return "Birdie";
} else if(strokes==par+1){ return "Bogey";
} else if(strokes==par+2){ return "Double Bogey";
} else if(strokes>par+2){ return "Go Home!";
}
``````

error

``````golfScore(4, 4)
``````

should return â€śParâ€ť

``````golfScore(5, 5)
``````

should return â€śParâ€ť

should there be ===

`par` is not quite `Par`

1 Like