Basic Javascript: Golf Code Syntax Error at End

I have completed this challenge, but I keep getting "Syntax Error: unknown: Unexpected token (21:16), but it is pointing to the space after the final character of the code (the area you aren’t supposed to change.) I have cleared my cache and redone the entire challenge without any copy and paste. I’ve gone through every line and can’t find any errors, and can’t see why it would give me an error on the part of the code I didn’t write. I have tried erasing the golfScore line, adding a space or a new line after. It just moves the phantom token around, doesn’t get rid of it.

I’m running Chrome Version 90.0.4430.212 (Official Build) (x86_64) on a 2020 Macbook Pro with Big Sur.

var 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 names[0]; }
else if (strokes <= par - 2) {
  return names[1]; }
else if (strokes == par -1) {
  return names[2]; }
else if (strokes == par) {
  return names[3]; }
else if (strokes == par +1) {
  return names[4]; }
else if (strokes == par + 2) {
  return names[5]; }
else if (strokes >= par + 3) {
  return names[6]
  // Only change code above this line
}

golfScore(5, 4);

This is the error I get in console

SyntaxError: unknown: Unexpected token (21:16)

  19 | }
  20 |
> 21 | golfScore(5, 4);
     |                 ^

Hi and welcome :wave:

your last else-if statement misses a closing }

Thank you. I feel so silly. I checked all of those and completely forgot that the final one that was on there was for the whole thing, not just for my last statement. :woman_facepalming:t2:

We’ve all spent hours trying to fix a bug that turned out to be a stupid mistake, get used to it :smiley:

2 Likes

I personally think these sorta of bugs are more common when you have a bunch code that all looks very similar because everything just starts to blend in.

I indent my entire function bodies to help me see this sort of brace mismatch, personally. I still make them, but they are easier to catch.

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