+ 1
Please why isn't this code working
https://code.sololearn.com/W7K63I21Ju5V/?ref=app the steps aren't forming
3 Respostas
+ 4
Also fix the for loop, if you're iterating backwards the condition should be i >= 0 rather than i < 0.
↓
for(i=courses.length-1; i<0; i--){
var courses[i] = "#";
}
+ 3
+ Removing the 'var' keyword from the loop body is required because you've already declare the variable, and you cannot declare an array by accessing a specific item (through the use of index inside squared brackets)
+ Declaring the 'i' variable is a good practice to be sure of in wich scope you want to define it (without explicit declaration, a undeclared var is maked in global scope)
+ to perform backwards iterating, a short way is to set the counter ('i' var in your code) to the length of the array (max value plus one) and use a while loop with a condition decrementing it... post decrement will test if value is not zero before decrementing, so the first used value is length minus one, and the last used is zero (1 is not zero, 1 is decremented so now equal zero, wich is the value used in the loop, and on next test, zero is zero, zero is decremented to -1, but loop is ended and loop body is not executed for -1)
var courses = new Array();
courses[0] = " ";
courses[1] = " ";
courses[2] = " ";
courses[3] = "#";
var i = courses.length
while (i--) {
courses[i] = "#";
}
console.log(courses);
+ 1
thanks alot y'all