Build a Golf Score Translator - Build a Golf Score Translator

Tell us what’s happening:

Is it right the last step of the lab?
I think we should use “>= par+3” instead of “> par+3”.

Your code so far

const names = ["Hole-in-one!", "Eagle", "Birdie", "Par", "Bogey", "Double Bogey", "Go Home!"];

function golfScore(par, stroke) {

if (stroke === 1) return names[0];
else if (stroke <= par-2) return names[1];
else if (stroke === par-1) return names[2];
else if (stroke === par) return names[3];
else if (stroke === par+1) return names[4];
else if (stroke === par+2) return names[5];
else if (stroke >= par+3) return names[6];
}

console.log(golfScore(4, 7));

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36

Challenge Information:

Build a Golf Score Translator - Build a Golf Score Translator

Hi @Panah

I think the user story should be rewritten:

golfScore should return “Go Home!” if strokes is greater than par plus 2.

Since the test expects the result:

13. golfScore(4, 7) should return the string Go Home!

You could include an else statement to handle the edge case.

Happy coding

1 Like