What's the best way to solve this?

Tell us what’s happening:
Describe your issue in detail here.

  **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
function golfScore(par, strokes) {

if (strokes < 2) {
return "Hole-in-one!";
} else if (par == par && strokes <= par-2) {
return "Eagle";
} else if (par == par && strokes <= par-1) {
return "Birdie";
} else if (par == par && strokes === par) {
return "Par";
} else if (par == par && strokes === par+1) {
return "Bogey";
} else if (par == par && strokes === par+2) {
return "Double Bogey";
} else if (par == par && strokes >= par+3) {

return "Go Home!";
} 


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/93.0.4577.82 Safari/537.36

Challenge: Golf Code

Link to the challenge:

You didn’t tell us what you need help with.

The code you pasted doesn’t work because you are defining the function twice:

function golfScore(par, strokes) {

Once you remove that then it passes. Maybe this was just a copy/paste error?

As for the logic:

if (par == par ...

What is the purpose of this comparison? When is this ever going to be false?

Hey Jyothirmay! How are you doing?
So, basically your function golfScore is being created 2 times, and you have the Change Me return value. What you need to do is delete one of those functions definitions, and then, delete the return 'Change Me';. But it’s not almost done, when you define a function that returns some value, you need to assign a variable to this function. Let me show you:

SOLUTION REDACTED

Hi @Nicolas_Evrard !

Welcome to the forum!

We don’t encourage users to post full solutions on the forum.
Instead it is best to guide the user through hints.

But also, this post was made back in September so they probably no longer need assistance anymore. :grinning:

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.