# Golf Code. Why won't it return "Par"?

Golf Code. Why won't it return "Par"?
0

#1

Tell us what’s happening:
Hello. I can’t figure out why my code doesn’t work. It seems to be identical to the solution, however my code doesn’t return “Par” when strokes = par. I can’t see why.

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
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 () {return "Go Home!";}

// Only change code above this line
}

// Change these values to test
golfScore(4, 4);
``````

Your browser information:

User Agent is: `Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:61.0) Gecko/20100101 Firefox/61.0`.

#2

I just added strictly equal operators through out (==) instead of the single equal signs. This fixed it but does anyone want to enlighten me as to why this works and not my solution?

#3

= is the assignment operator
== is the equality operator
=== is the strict equality operator

They are different though the == and === are similar and they are both comparisons operators. I suggest reading more about the various comparison operators.

#4

Oh right, thank you. I will review that.