# Can't understand the question - Golf Code

Tell us what’s happening:
I can’t understand the whole question. I read the full details given in the lesson. i can’t understand.

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

``````

User Agent is: `Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:83.0) Gecko/20100101 Firefox/83.0`.

Challenge: Golf Code

Hi there,
first of all, let’s talk about golf.
You need to shoot the ball, but often your shot is either far behind the hole or below the hole. If you need par - two strokes to send the ball then it is called “Eagle” .
Par is the average number of strokes.
For example, if you need >= more than Par + 3 strokes then you need " go home". Basically, this is what it’s called.
Now in this lesson, you call the function which is `golfScore( );` and you pass two arguments to the function. Those two arguments are par and strokes.

If this argument equals this `strokes <= par - 2` then it should return “Eagle”. The default value for strokes is 1.
You can use conditional statements to return the callings.

2 Likes

Hi @codely!

Go through the chart of possible strokes and create conditions for each possible scenario from 1 all the way through to >= par + 3 using the formulae that @anon58011934 laid out for you.

Hope that helps!

1 Like

This is my updated 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(par = 1){
return "Hole-in-one!";
} else if (strokes <= par - 2){
return "Eagle";
} else if (par - 1){
return "Birdie";
} else if (par) {
return "Par";
} else if (par + 1) {
return "Bogey";
} else if (par + 2) {
return "Double Bogey";
} else if (strokes >= par + 3) {
return "Go Home!";
} else{
return "Change Me";
}

// Only change code above this line
}

golfScore(5, 4);

``````

You are starting to get the right idea.

If you look at the chart though it says if strokes is 1 then return “Hole in one”. So try to see if you can incorporate strokes in all of your if statements.

Like you did here.

1 Like

Also your last else should be go home not change me.

Hope that makes sense.

1 Like

Now??

``````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 (par - 1){
return "Birdie";
} else if (par) {
return "Par";
} else if (par + 1) {
return "Bogey";
} else if (par + 2) {
return "Double Bogey";
} else if (strokes >= par + 3) {
return "Go Home!";
}

// Only change code above this line
}

golfScore(5, 4);
``````

All if/else statements should all include strokes with the exception of the last else statement.

For the last else statement it shouldn’t be else if it should just be an else.
Remember that an else block is going to look different than an if or else if.

Here is a hint on how to write that last else statement.

None of these `if` statements include a comparison.

2 Likes

now this is my updated 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 "Hole-in-one!";
} else if (strokes <= par - 2){
return "Eagle";
} else if (par - 1){
return "Birdie";
} else if (par = strokes) {
return "Par";
} else if (par + 1 + strokes) {
return "Bogey";
} else if (par + 2 + strokes) {
return "Double Bogey";
} else if (strokes >= par + 3) {
return "Go Home!";
} else {
return "Go Home!";
}

// Only change code above this line
}

golfScore(5, 4);
``````

this is not a comparison

here you are changing `par`

the two below are also not comparisons

you need to compare the variables

1 Like

how to check if it is a comparison?

write the statement in a console.log, if it prints true/false it is one

for example:

``````console.log(strokes == 1) // this is a comparison

console.log(par - 1) // this is not
``````
1 Like

None of these have any conditional operators in them. They aren’t testing for anything. Try reading them out loud to see if they make sense “If par plus one plus strokes”.

Also remember that `=` does not check for equality. It is the assignment operator.

1 Like

I think this is the key to solving the problem.

I would suggest going through the strokes and return chart in the challenge and saying out loud each of those statements before translating that into code.

For example, “If strokes equals this return that”

Cause I don’t see this in the chart

“If par plus one plus strokes”

I do see however,
“If strokes equals par plus 1”

2 Likes

Thank you @jwilkins.oboe @ilenia @anon58011934 @ArielLeslie for your help.

I competed the test.

1 Like