function golfScore(par, strokes) {
// Only change code below this line
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];
else {
return “Change Me”;
}
// Only change code above this line
}
var names = [“Hole-in-one!”, “Eagle”, “Birdie”, “Par”, “Bogey”, “Double Bogey”, “Go Home!”];
function golfScore(par, strokes) {
// Only change code below this line
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];
else {
return “Change Me”;
}
// Only change code above this line
}
// Change these values to test
golfScore(5, 4);
// running tests
golfScore(4, 4) should return “Par”
golfScore(5, 5) should return “Par”
golfScore(4, 5) should return “Bogey”
golfScore(4, 6) should return “Double Bogey”
golfScore(4, 7) should return “Go Home!”
golfScore(5, 9) should return “Go Home!”
Some tests passes because your checks for “Hole in One” and “Birdie” are correct.
Here you make a mistake:
else if (strokes = par-1) {
return names[2];
}
Instead of checking if strokes is equal to par - 1, you’re assigning par - 1 to strokes, since par - 1 is not-zero, that conditional is passing every time. Which means for every other test you’re returning names[2], which is “Birdie”, and that’s why the test that expect “Birdie” also passes.
Instead of assigning par - 1 to strokes, you should compare them by doing this:
else if (strokes === par-1) {
return names[2];
}
Note that this is not the only error in your code.