js golf score if else code example
Example: js golf score if else
/*
* this is a (https://www.freecodecamp.org/) golf score challenge solution
* using only if / else
*/
var names = ["Hole-in-one!", "Eagle", "Birdie", "Par", "Bogey", "Double Bogey", "Go Home!"];
function golfScore(par,strokes) {
if(strokes === 1 && par === 4){
return names[0];
} else if(strokes === 1 && par === 1) {
return names[0];
} else if(strokes === par && par === strokes) {
return names[3];
} else if(strokes === 4 || strokes <= par - 2) {
return names[1];
} else if(strokes === 4 || strokes <= par - 1) {
return names[2];
} else if(strokes === 4 || strokes <= par + 1) {
return names[4];
} else if(strokes === 4 || strokes <= par + 2) {
return names[5];
} else {
return names[6];
}
}
golfScore(5, 9);