Shift in answers

Tell us what’s happening:
I feel that i close to right answer but i have shift in answers (-1) which i can’t change

Your code so far


function getFinalOpenedDoors(numDoors) {
 // Good luck!
 let doors = [];
 for (let i = 1; i < 101; i++){
   doors.push([i,"o"]);
 }
 let j;
//number of incrementing door's number for checking
 let k = 2;
 //function of checking state of door
 function it(){for(j = k; j < doors.length; j+=k){

(doors[j][1] == "o") ? doors[j][1] = "x": 
doors[j][1] = "o"
 }  
 };
 it();
 
 while(k <= 100){
   if(j >= doors.length){     
     k++;
     j = k;
     it();
   }
 }
//opened doors pushed in new array
 let far = [];
for(let u = 0; u < doors.length; u++){
  if(doors[u][1].includes("o")){
    far.push(doors[u].splice(0));
  }
}
 return far;
}

console.log(getFinalOpenedDoors(100))

Your browser information:

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

Challenge: 100 doors

Link to the challenge:

On this line:
function it(){for(j = k; j < doors.length; j+=k)
change j = k to j = k - 1
Also, you need to return an array of numbers of the door only.
You can do this by changing line 31 from:
far.push(doors[u].splice(0));
to
far.push(doors[u][0])
so that it returns [1, 4, 9] etc…

Good Luck :smiley:

It’s great that you are enthusiastic about helping people here. We try to guide folks to the answer rather than telling them exactly what to do here.

Great. Thank you. So little changes but so substantial