Basic JavaScript: Golf Code...noIdea

Tell us what’s happening:
I cannot understand, and don’t have idea of how me finish that question

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 (par >= 1 && strokes === 1 ){
    return names[0];
  } else if(par >= 2 && strokes === 2 ) {
    return names[1];
  } else if (par >= 3 && strokes === 3){
    return names[2];
  } else if (par >= 4 && strokes >= 4){
    return names[3];
  } else if (par >= 4 && strokes === 5 ){
    return names[4];
  } else if (par >= 4 && strokes >= 6 ){
    return names[6];
  }

}

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

Your browser information:

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

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

Hole in one is the only case where the response is based on the number assigned to strokes (and par doesn’t matter for that response). The other cases should be based on the difference between par and strokes.

1 Like

it seems you have misread the table in the challenge.
In golf par is the ideal number of strokes you need to put the ball in the hole, and it can ber any number.
So if you have a par of 12, but you do it in 24 strokes, you are not doing great, but if you do it in 11 strokes than it is “Birdie”! (that last case in your code is not possible to get)