Help understanding the golf code challenge solution

Help understanding the golf code challenge solution
0

#1

So I’ve solved the golf code challenge, and I think I understand the reason why it works mostly. However, one thing that seems slightly illogical to me is having

if (strokes == 1) {
return “Hole-in-one!”;
}

BEFORE

else if (strokes == par) {
return “Par”;
}

Why doesn’t golfScore (1, 1) return “Par”?

Also whilst looking to see if somebody else had asked this question, I noted that others had used the code:

if (strokes === 1) {
return “Hole-in-one!”;
}

Is it better to use === instead of == for this code just because the input is always numeric?

Another thing that popped up when looking to see if there was a similar question - am I supposed to remove the final “return” command in these challenges? Or edit them in some manner?

Thanks in advance!


#2
if (strokes == 1) {
return "Hole-in-one!" // ends execution of the function, no further checks are made
}

== is perfectly fine in this case (according to YDKJS see Equality)

You should modify the code to pass the test cases. If you need to remove something, remove it.


#3

Most of the people who are having difficulty with this one are also not using the array that was provided. All of the return statements can be referred to as names[0] or names[1], etc. If you do this, there’s no chance of a misspelling. Just as a side point, there is such a thing as a Double Eagle, which is 4 under par. Three under par is an Albatross. No one ever talks about these because it’s difficult to, for example, get a hole in one on a 500 yard dog-leg to the left with trees in the way. Not even considering the possibility, because I’ve never gotten an Albatross or Double Eagle, I forgot to put <= on the one that returns names [1] .