My code is OK, but the test shows error.
If you have a question about a specific challenge as it relates to your written code for that challenge and need some help, click the Ask for Help button located on the challenge (it looks like a question mark). This button only appears if you have tried to submit an answer at least three times.
The Ask for Help button will create a new topic with all code you have written and include a link to the challenge also. You will still be able to ask any questions in the post before submitting it to the forum.
Thank you.
This code works, but the test isnāt OK.
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 <= 0 || par <= 0 ){
return "Wrong input!"
}
else if (strokes === 1) {
return "Hole-in-one!"
}
else if (strokes <= par - 2) {
return "Eagle"
}
else if (strokes <= par - 1) {
return "Birdie"
}
else if (strokes <= par) {
return "Par"
}
else if (strokes <= par + 1) {
return "Bogey"
}
else if (strokes <= par + 2) {
return "Double Bogey"
}
return "Go Home";
// Only change code above this line
}
console.log(golfScore(4, 0));
console.log(golfScore(4, 7));
console.log(golfScore(5, 9));
Found the bug!
Typo. You arenāt returning the correct string.
Note - āmy code is perfect and you have to be wrongā isnāt usually a helpful approach to take when debugging. I get a lot more success with āsomething isnāt working correctly hereā. Thereās always a bug somewhere, and I have more success when I assume Iāve made the mistake.
Hi.
I did never beleive that my code was perfect, but good enough according to the lesson instructions. The feedback by testing werenāt very helpful because console logging of function calls with the āerrorā values returned correct answer in my code.
So I donāt quite agree with you. According to the lesson text the code should not be wrong?
But I was able to continue to the next lesson by copying and pasting the solution code into my answer.
You can try my code to understand my confusion.
My code returns an error message if the values are unrealistic - a test for me own sake when typing the code. My output for the spesific values was OK, so I studied the lesson text more carefully.
If (strokes - par) is 3 or more then we leave the loop with āGo Homeā as return value. I think it should be OK. The lesson instructions didnāt say we should only test within the array values. The output from my code was OK, but the test said it wasnāt.
Nope. According to the lesson text your code is wrong.
Look at the last line of the chart you were given. You are not using in your code the exact string given in that chart. That sort of thing is easy to overlook, which is why we gave the array of values so you have a way to avoid typos like that.
@Jostein Do you understand what is wrong with the return value or is it still not clear?
Compare the last element in the array with your last return statement. You are missing the punctuation.
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.
