# Help understanding the golf code challenge solution

**URL:** <https://forum.freecodecamp.org/t/help-understanding-the-golf-code-challenge-solution/12455>\
**Category:** General\
**Created:** [June 19, 2016, 2:23pm UTC](https://forum.freecodecamp.org/t/help-understanding-the-golf-code-challenge-solution/12455 "2016-06-19T14:23:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mike\_hurl](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/mike_hurl/32/165906_2.png) [@mike\_hurl](https://forum.freecodecamp.org/u/mike_hurl)\
**Post date:** [June 19, 2016, 2:23pm UTC](https://forum.freecodecamp.org/t/help-understanding-the-golf-code-challenge-solution/12455/1 "2016-06-19T14:23:29Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![jenovs](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jenovs/32/60963_2.png) [@jenovs](https://forum.freecodecamp.org/u/jenovs)\
**Post date:** [June 19, 2016, 2:44pm UTC](https://forum.freecodecamp.org/t/help-understanding-the-golf-code-challenge-solution/12455/2 "2016-06-19T14:44:41Z")

</div>

```auto
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](https://github.com/getify/You-Dont-Know-JS/blob/master/up%20&%20going/ch2.md) see **Equality** )

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

---

<div class="post-metadata">

**Author:** ![ohNowIGetIt](https://avatars.discourse-cdn.com/v4/letter/o/e9a140/32.png) [@ohNowIGetIt](https://forum.freecodecamp.org/u/ohNowIGetIt)\
**Post date:** [May 30, 2018, 9:41pm UTC](https://forum.freecodecamp.org/t/help-understanding-the-golf-code-challenge-solution/12455/3 "2018-05-30T21:41:16Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [January 16, 2021, 1:10pm UTC](https://forum.freecodecamp.org/t/help-understanding-the-golf-code-challenge-solution/12455/4 "2021-01-16T13:10:07Z")

</div>

Closed on January 16, 2021, 1:10pm UTC


