Need help regarding golf code

Here is my code

if (par==strokes){
return "Par"
} else if (strokes <= par-2){
  return "Eagle"
} 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+3){
  return "Go Home!"
} else if (strokes ==1 && par>=1){
  return "Hole-in-one!"
}

The error I’m getting is

golfScore(4, 1) should return the string Hole-in-one!
golfScore(1, 1) should return the string Hole-in-one!

Where am I going wrong??

Edit: I switched the Hole in One else if with the Par if and the code worked.

you are printing out Go Home when the strokes are >= par+3
so 1+3 is 4 and that’s why it is failing

I thought the code should return Go Home if the Strokes are 3 more than the Par.

I just Switched the positions of the Hole in One and the Par statements and my answer was accepted

if (strokes ==1 && par>=1){
  return "Hole-in-one!"
} else if (strokes <= par-2){
  return "Eagle"
} 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+3){
  return "Go Home!"
} else if (par==strokes){
 return "Par"
}

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.