Golf Code Seems So Confusing

Tell us what’s happening:

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


return "Change Me";
// Only change code above this line
}

golfScore(5, 4);

Doing Some basic JS recap but it appears that golf code challenge got me confusing the most. Please help!!

Your browser information:

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

Challenge: Golf Code

Link to the challenge:

what’s your question?
what help do you need?
what have you tried so far?

Like, I was considering the how the code should be arranged in order of importance.

My 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 (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 {
  return "Go Home!";
}

  // Only change code above this line
}

golfScore(5, 4);

You don’t have to use the literal return like
return “Hone-in-one”

You can use the names array.

It’s like this
stroke s = 1 --> that’s Hole-in-one
-2 and below --> that’s Eagle
-1 --> that’s Birdie
0 or strokes and par are the same --> that’s Par
1 --> that’s Bogey
2 --> that’s Double Bogey
3 and above --> that’s Go Home

So golfScore(5,4) is Birdie
Since you made only 4 strokes for a par of 5

golfScore(5,2) is Eagle
Since you made only 2 strokes for a par of 5

golfScore(5,5) is Par
Since you made 5 strokes for a par of 5

golfScore(5,6) is Bogey
Since you made 6 strokes for a par of 5

golfScore(5,7) is Double Bogey
Since you made 7 strokes for a par of 5

golfScore(5,8) is Go Home
Since you made 8 strokes for a par of 5

golfScore(5,9) is also Go Home
Since you made 9 strokes for a par of 5

Hope this helps.

GOD bless.

1 Like

do you want to compare or assign?

remember the difference between comparison and assignment operator

1 Like

Hello everyone,
for my was hard to understand how to do a logic… I know that this was if/else if/else task, but just doesn’t get how to write logic.
But when I put my one eye a little bit to this post i wrote code like this.

If I can’t to figure out this simple task maybe I’am not smart enough? Why it’s so hard?
:smiley:
And I think that this solution can make much more solid to use for loop for(var i = 0; i < names.length; i++);, but I can not figure how… :frowning_face:

My code:

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]

}else{

  return "Change Me";
  // Only change code above this line
}}

console.log(golfScore(4,3));```