Basic JavaScript - Golf Code

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

i dont understand what this exercise is asking non of the other tutorials ive went through have code that is similar to this one. i dont know what to ask when doing in internet search. can anyone explain this to me like im a third grader?

  **Your code so far**
const names = ["Hole-in-one!", "Eagle", "Birdie", "Par", "Bogey", "Double Bogey", "Go Home!"];

function golfScore(par, strokes) {
// Only change code below this line
  
 if( 4 < 1){
      return "Hole in one!"
    }

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/105.0.0.0 Safari/537.36 Edg/105.0.1343.33

Challenge: Basic JavaScript - Golf Code

Link to the challenge:

You need to make comparisons using the two parameters, stroke and par, to determine what to return.

1 Like

i dont know how to do that

if( 1 == “Hole-in-one!”) {
return “Hole in one”;
} else (<= par - 2 == “Eagle”) {
return “Eagle”;
} else ( par- 1 == “Birdie”) {
return “Birdie”;
} else (par == “Par”) {
return “Par”;
} else (par + 1 == “Bogey”) {
return “Bogey”;
} else (par + 2 == “Double Bogey”) {
return “Double Bogey”;
} else (>= par + 3 == “Go Home!”) {
return “Go Home!”;
}

return “Change Me”;

i tried this but it didnt work

You got the basic look of it. You are supposed to compare strokes and par though. You returns are all right. Remember == means something matches whatever parameters. Such as:

1 == 1
1 == '1'
"1" ==  1

function golfScore(par, strokes) {

if( strokes == “1”) {
return “Hole in one”; ???

is this exercise based partially off the operators section? if so i would have to relearn the operator section because i forgot it all.

Yes, though I wouldn’t use quotes on a number. Now all you have to do is continue with else if statements till you’re done.

Also yes it is based a little bit on the operators section.

ALRIGHT HERES WHAT I DID BUT NO LUCK STILL

function golfScore(par, strokes) {
// Only change code below this line
if( strokes == 1) {
return “Hole in one”;
} else (strokes <= par - 2) {
return “Eagle”;
} else (strokes == par - 1) {
return “Birdie”;
} else (strokes == par) {
return “Par”;
} else (strokes == par + 1) {
return “Bogey”;
} else (strokes == par + 2) {
return “Double Bogey”;
} else (strokes >= par + 3) {
return “Go Home!”;
}
return “Change Me”; }

Your else statements should be else if if there are more parameters being tested. Also you have an extra return statement at the end there

if( strokes == 1) {
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 if(strokes >= par + 3) {
return “Go Home!”;
}

i would have never known to type …stroke… in the code because the instructions and past lessons did not make it obvious.

Hi. Here’s my own solution. You might find it useful, or not. However, I like it because it combines a bit of everything from the previous lessons, which is a good way to solidify the concepts learned.

Moderator edit answer out

It’s nice that you have solved the challenge, but the forum aims to help people deduct ways to solve their challenge, we are against outright showing solutions.

1 Like

Oh okay I understand. Thank you.

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