Golf Code Issues

My main issue is golfScore(4, 4) and (5, 5) not returning par.

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

function golfScore(par, strokes) {
  // Only change code below this line
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(strokes >= par + 3);{
  return "Go Home!";

  // Only change code above this line

golfScore(5, 4);

Your code has syntax errors - specifically the usage of if-else if-else .

Could be more specific? I am not getting any syntax errors in the console. In addition, when I test for the scores (4,4) and (5,5) with console.log(golfScore(#,#)) they both return par. However, when I run my test I get an error saying my scores should return par.

That is a syntax error.

SyntaxError: unknown: Missing semicolon. (17:25)

15 | }else if(strokes === par + 2){
16 | return “Double Bogey”;

17 | }else(strokes >= par + 3){
| ^
18 | return “Go Home!”;
19 | }

Welcome :wave:

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 (').

1 Like


You can refer/search online or your course notes for the correct usage of the if-else construct. Note that the usage of the else towards the end of the if-else.

}else{ return "Go Home!"; }
I have fixed the syntax error, but still get the issue with my test run telling me my (4, 4) and (5,5) are not returning par. However, console.log says otherwise.

// running tests golfScore(4, 4) should return the string Par golfScore(5, 5) should return the string Par


:+1: Your code works fine.

Also, you can use the array variable names values within your function instead of the string return values.

I appreciate your input, however I am still unable to progress past this part. I am unsure as to why exactly, perhaps this section is bugged?

Are you sure what is expected and what is returned values are same? Using the names array values in the code will definitely pass!

1 Like

OMG the “P” in my par string is not capital!!!

The correct way of using the provided array of values, for example:

if (strokes == 1) {
    return names[0];

This way, you will not make any mistakes regarding the returned values. They will be correct always.

1 Like

It should be “Par”, not “par”
You should replace the strings with their array indexes, so that you do not mess up with the spellings and stuff

i.e, instead of “Hole-in-one!” it should be names[0]