Hello and thank you! That fixed my problem, for the most part. My final solution is below and it passed.
I have a question about the two of the “else if” statements, italicized in the output below. Why did I have to add the “&&” to explicitly check to see if the stroke was equal to 3 or 4 for the function to work? It seems like that will limit the program for other possible inputs. Or am I missing a huge point of this lesson like that I should only care about the test scenarios?
Thanks.
Here is my final code:
var names = ["Hole-in-one!", "Eagle", "Birdie", "Par", "Bogey", "Double Bogey", "Go Home!"];
function golfScore(par, strokes) {
// Only change code below this line
// return names;
if (strokes === 1) {
return names[0];
} else if (strokes == 2) {
return names[1];
} else if (strokes == par -1 && strokes == 3) {
return names[2];
}else if (strokes == par -1 && strokes == 4) {
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 {
return names[6];
}
}
golfScore(5, 4);
I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.
You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.