Tell us what’s happening:
It works till it gets to name[3] for “par”
I’ve tried using “==” and “===” and it does not help.
I feel I’m missing something obvious and am prepared to be embarrassed.
Your code so far
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 {
return names[6];
}
return "Change Me";
// Only change code above this line
}
golfScore(5, 4);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36
Actually, that line doesn’t do what you want it to do.
What does = do?
What does == do?
What does === do?
I’d think about how you “know” that line works. The tests might make it seem like that line is ok and the next if statement is wrong, but that’s not true.
Well I only have the info I’m given, so if I’m told the line worked, I have no cause to question it. I compared it to the ‘solution’ example and it’s almost identical. I don’t feel like you want to help me, so its ok, thanks for your time.
Like I said, = is wrong. That cannot work here because = changes the value of one of the variables you are comparing.
So can you show your “other code” with == that doesn’t work? I can’t say what’s wrong with your code that uses == if you don’t share it.
Nothing is telling you that line “worked”. The tests only tell you which test cases passed, not which lines of your code are right or wrong. The humans on the forum can tell you which lines are right or wrong!
I’m not sure actually, I was fairly frustrated when I worked it yesterday.
But the “=” was definitely the problem and it works now. I’m not sure I understand why. I thought I understood the difference between the “=”, “==”, and “===” but apparently I do not…
I am a slow learner.
= Assignment operator: myVariable = 42 puts the value 42 into myVariable
== Weak comparison operator: thing1 == thing2, compares thing1 and thing2, doing type concision as needed (though some sometimes confusing conversion rules), so it checks if thing2 can be converted into being the same as thing1
=== Strong comparison operator: thing1 === thing2, compares thing1 and thing2 to see if they are exactly the same (1 === 1 is true while 1 === "1" is false)
Learning takes time. Its part of the process. Unfortunately, debugging involves a lot of questioning your assumptions about how your code works, so debugging can feel a little discouraging. Totally normal
It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.
We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.