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?
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] .