Remember, the par passed into the function can be different numbers, it won’t always be 4. Short holes are usually par 3 and longer holes are often par 5. So I’m not sure you really want to limit this to only holes that are par 4.
This isn’t how you say “if par equals 4 or par equals 5”. You literally have to spell it out the way I said it between the quotes.
This only works if the par is 4 and the strokes is 5. What if the par is 3 and the strokes is 4?
What you are doing here is hard coding the possible numeric combinations into the code. Instead, think about how you can compare the par to the strokes passed into the function without having to know what their actual values are.
I changed it so its not limited to specific values but so that it’s more abstract like in the video but still doesnt work.
const 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 if (strokes >= par +4){
return names[7]
}else if (strokes >= par +5){
return names[7]
}else{
return "Change Me";
}
// Only change code above this line
}
golfScore(5, 4);
Best I could do was remove smaller and greater than and equal -1 and +1 but still (4,7)&&(5,9) not working.
const 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
}
golfScore(5, 4);