Why are the test runs failing for my function? I checked in Chrome’s developer console and it runs perfectly with the same results that the test show’s should be returning. Question is to write a function that returns the largest numbers in an array. I attached a screenshot with the failed tests.
I still don’t understand because when I run it in Chrome developer console it is returning an array with the same exact numbers as the test. I need another hint, but don’t give me the answer.
Quick question. I’m checking through Chrome developer console before I actually submit the problem. In Chrome console the solution comes out exactly if I define the variable or not. What can you recommend me to use instead of Chrome developer console to avoid this in future?
The Chrome developer tool is what you would primarily use when building and testing things out, the reason why it’s showing up on the console and undefined in your function is because a variable not being declared will become global, so it shows up in your console. And by using a globally defined variable within a function can result in some weird results.
So best advice is to just always remember to declare your variables, I’m not sure how far into the JS you are in, but should ditch var for let and const, as they each come with it’s own scoping, unlike var, so using those will prevent any headaches in the future.