showing results for - "js golf score if else"
Mina
16 Jan 2016
1/*
2 * this is a (https://www.freecodecamp.org/) golf score challenge solution 
3 * using only if / else
4*/
5
6var names = ["Hole-in-one!", "Eagle", "Birdie", "Par", "Bogey", "Double Bogey", "Go Home!"];
7function golfScore(par,strokes) {
8
9if(strokes === 1 && par === 4){
10  return names[0];
11} else if(strokes === 1 &&  par === 1) {
12  return names[0];
13} else if(strokes === par &&  par === strokes) {
14  return names[3];
15} else if(strokes === 4 || strokes <= par - 2) {
16  return names[1];
17} else if(strokes === 4 || strokes <= par - 1) {
18  return names[2];
19} else if(strokes === 4 || strokes <= par + 1) {
20  return names[4];
21} else if(strokes === 4 || strokes <= par + 2) {
22  return names[5];
23}  else {
24  return names[6];
25}
26
27}
28
29golfScore(5, 9);
queries leading to this page
js golf score if elsejs golf score if else