I believe I’ve managed a solution, and using the console from chrome I get my array back of [1, 4, 9, 16, 25, 36, 49, 64, 81]. However, the code checker tells me it does not return the expected result. I just want to make sure that I’m not missing something about the way freecodecamp’s checker works. Is there something else I should be doing?
Your code so far
var numdoors = 100;
function getFinalOpenedDoors (numDoors) {
//our count of open vs closed doors
var openDoors = [];
//our array of doors. It will count upward. An even number is closed, odd is opened.
var doors = Array(numdoors).fill(0);
//only finds and toggles relevant doors for each runthrough. Subtract one to account for runthrough starting at 1 and doors starting at index 0.
for (var runthrough = 1; runthrough < doors.length; runthrough ++) {
var counter = runthrough;
while (counter <= doors.length) {
doors[(1 * counter) - 1] ++;
counter += runthrough;
}
}
//if the door is an odd number, it is open. Add its index plus 1 to our door counter (door one is at index 0, so 0+1)
for(var i = 0; i < doors.length; i++) {
if (doors[i] % 2 == 1) {
openDoors
.push(i+1);
}
}
return openDoors;
}
getFinalOpenedDoors(numdoors);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:65.0) Gecko/20100101 Firefox/65.0
.
Link to the challenge: