Pars and strokes

Tell us what’s happening:
I passed the test quite alright with some help from the hint but can someone please throw more light on pars and strokes so I can understand it better. Thank you

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 "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);

Your browser information:

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

Challenge: Golf Code

Link to the challenge:

pars and strokes are a golf thing
with the par being the average number of strokes the player you need to put the ball in the hole, and strokes being the number of throws they need.

This is not a code thing, but if you are interested to learn more about golf, I suggest wikipedia.

but if you want some suggestions at getting better…
you have an array with the values as first line of your code, you could use that array instead of risking typos while hardcoding the strings

I must be honest your replies have been super helpful. I think I will prefer using the array method. I will appreciate more insightful tips from you as I hope to get better eg//will this equally execute
if (strokes==1){
return “Hole-in-one!”;
}else if (strokes<=2){
return “Eagle”;
}… etc will this code also execute.


do you mean the strokes <= 2?
it will not give the required output as you need to compare strokes to par to know what string to returns, here you are not

what i meant earlier was this
// It worked out fine
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];


return names[6];

Although i find it hard to grasp how the else statement means (strokes >=+3)

it doesn’t, but the else statement execute if no one of the previous ones executed, so it works like that

Thank you a lot dear your patience is phenomenal i appreciate.
// How does this code affect the function
// Only change code above this line


golfScore(5, 4);

That was the last statement of the exercise i will just like to know its meaning and function :man_facepalming:t5: :man_facepalming:t5: :man_facepalming:t5:

do you mean this?
this is the function call, the function is called and the values of its parameters are specified inside the parenthesis

if you have doubts on functions you could review the challenges that introduce them or try finding some articles that explains them

1 Like