Hello, can you please help me?
The logic for 100 doors is: every Perfect Square number will be open at the end.
Therefore, I’m trying to write a code that only displays perfect squares (1, 4, 9, 16, …)
1 - Create array doors
2 - if number is perfect square then push into array
3 - return array doors
Can someone please tell me what is wrong with my code?
Thanks!
function getFinalOpenedDoors(numDoors) {
var doors = [];
for (numDoors = 0; numDoors < 100; i++) {
if (Math.sqrt(numDoors) % 1 === 0){
doors.push[numDoors];
}
}
return doors;
}
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.129 Safari/537.36.
Challenge: 100 doors
Link to the challenge:
https://www.freecodecamp.org/learn/coding-interview-prep/rosetta-code/100-doors