Basic JavaScript - Use Recursion to Create a Countdown

Tell us what’s happening:
Describe your issue in detail here.
Could anyone explain why my code is not validating as correct, whereas if I run it locally in VsCode, it gives the correct results which are in the descending order. I have not used any global variables also and have used recursion as was mentioned in the challenge.
Your code so far

// Only change code below this line
function countdown(n){
if (typeof countArray==='undefined'){countArray=[];}
if (n<1){return countArray;}
return countArray;
// Only change code above this line

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/ Safari/537.36

Challenge: Basic JavaScript - Use Recursion to Create a Countdown

Link to the challenge:

I assume that because you are unintentionally making a global variable, that is why this is working in VScode and not on here.

I think all tests on this site are running in strict mode, which is why you should be getting the error: ReferenceError: assignment to undeclared variable countArray. You are declaring countArray in that if without var, let or const, which will make a global variable.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.