JS Golf Code Problem

Tell us what’s happening:
Hello Guys! I’m woking on this particular problem that require us to add different statements such as If, Else If and Else. I’m not sure why is not working properly because i/m pretty sure that everything is correct. If someone can identify the problem, please let me know, Thanks U So Much Guys!

Your code so far


var names = ["Hole-in-one!", "Eagle", "Birdie", "Par", "Bogey", "Double Bogey", "Go Home!"];
function golfScore(par, strokes) {
  // Only change code below this line
  if(stroke ==1){
    return "Hole-in-one!";
  } else if (stroke <= par -2){
    return "Eagles";
  } else if(stroke == par -1){
    return "Birdie";
  } else if(stroke == par) {
    return"Par";
  } else if (stroke == par +1){
    return"Bogey";
  } else if (stroke == par +2){
    return"Double Bogey";
  } else {
    return "Go Home";
  }
  
  // Only change code above this line
}

// Change these values to test
golfScore(5, 4);

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/golf-code

Hint: extra letter somewhere.

2 Likes

Plus I highly recommend using === and never ==.