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.