Solved this problem using the below method. But would any JavaScript developer who is experienced could write this in a cleaner way? I was thinking you can loop through the "names" array and make the code cleaner but no matter how much I try it doesn't make sense outside of this box. Any tips would be greatly appreciated! Just trying to challenge myself into the next phase...
var names = ["Hole-in-one!", "Eagle", "Birdie", "Par", "Bogey", "Double Bogey", "Go Home!"];
function golfScore(par, strokes) {
if (strokes == 1) {
return names[0]
} else if (strokes <= par - 2) {
return names[1]
} else if (strokes == par - 1) {
return names[2]
} else if (strokes == par) {
return names[3]
} else if (strokes == par + 1) {
return names[4]
} else if (strokes == par + 2) {
return names[5]
} else if (strokes >= par + 3) {
return names[6]
}
}