const 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);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.5845.686 YaBrowser/23.9.5.686 Yowser/2.5 Safari/537.36
Challenge Information:
Basic JavaScript - Golf Code
Personally, I don’t understand this procedure, which means par-2? There is no explanation here that he is subtracting this two from where, who knows?
I’m not sure exactly which part of it you don’t understand, whether it’s how to code it or how to understand the scoring.
From the challenge description:
Every hole on a golf course is assigned a par score (3, 4 or 5), which is an indication of the difficulty (or length) of the hole in terms of how many strokes it could reasonably take (on average) to complete the hole.
So, for a par 3 hole, if you complete the hole in 3 strokes, you have achieved ‘par’. If it takes you 4 strokes, it’s a ‘bogey’. If it’s 2 shots, it’s a ‘birdie’… and so on.
So, to code this challenge, you simply compare the number passed to the par parameter with the number of strokes actually taken and (using conditional statements e.g.) return a string from the function which corresponds with the above table (e.g. if strokes equals par+2 then you would return “Double Bogey”).
I got to this exercise and there’s nothing clear to me here, <= par - 2 in the function it is indicated (5,4) if this is translated then 4 <= “5-2=>”3 that is, and this again is not clear to me