Just celebrating!

So my first real challenge that I got stuck on was the Golf Game in Javascript. Took me two days wondering around my house thinking about different solutions of how I can have different outcomes with the same numbers. But here is my solution and I am happy to move on!

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

  // Only change code above this line

golfScore(5, 4);

Ps - For anyone diving into Javascript, make sure and code along in your text editor. Also, read a Javascript book while you do these challenges. Doing these two things has really helped me progress and retain a whole lot more than just trying to fly through each challenge. I wish someone would have told me this before I started-- I wouldn’t have wasted two weeks of it flying through one ear and out the other.

1 Like

I agree that playing around in the console and reading a JS book is helpful to progression. I also recently have been able to complete some harder challenges since spending more time reading and understanding it.

I’d recommend checking out this free JS guide.

That’s awesome you’re progressing to more difficult challenges.

Thanks for the recommendation. I will check that out!


1 Like

We are a teaching forum so we don’t normally post answers here, but if you feel the need, please enclose in “spoiler” tags, [spoiler] and [/spoiler], one on the line before and one after. This will blur your answer to warn people that it is a solution. And if you do the same with three backticks, it formats your code for you. I’ve done it for you here.