I am utterly not grasping what this task

Continuing the discussion from freeCodeCamp Challenge Guide: Golf Code:
honnestly this is the most difficult task that i have not been able to understand in Javascript even after going through the solutions i still dont fully grasp it. but i get the idea. if anyone can help i will appreciate more.

I think you might need to be a little more specific about what you don’t understand. It sounds like you already looked at the possible solutions in the hints. What don’t you understand about those?

There are few things you can pin point when exploring the task. First, your function is meant to return a string, one of the listed. To be returned, each string has a condition listed. All the conditions has that in common, they compare the strokes with the par, which are parameters provided when calling the function. For example, if the strokes are equal par + 2, we return the string ‘Double Bogey’. If the strokes are less or equal par - 2, we return ‘Eagle’. And so on… A straight forward solution would be to list a number of conditions, for every case/string listed. The order of conditions can also be of importance

1 Like

slept over it and now i fully understand. thank you.

This really helped alot

They are asking you to write a function whereby given any stroke, either less than or greater than whatever par that is specified, it will correspond with the output(or return) section in the table given.
This is how i did mine:

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 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]
}

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

console.log(golfScore(5, 9));