Code challenges: Intermediate Javascript Browser Freezes

Hi, I just started the Code challenges.

I am doing exercise 3.
https://www.codecademy.com/paths/web-development/tracks/web-dev-js-arrays-loops-objects/modules/web-dev-intermediate-javascript-practice/lessons/intermediate-javascript-coding-challenge/exercises/greet-aliens

But my browser is freezing when I want to run the code:

I am checking if I made an infinite loop, but I don’t see what I have done wrong (Sorry Codecademy, I really ddn’t mean to break the website :confused:)

Can you help me? This is my code:

// Write your code here:
const greetAliens = array => {
 
  for (let i = 0; i < aliens.length; i++) {
    console.log(array.push(aliens));
  }
}









// When you're ready to test your code, uncomment the below and run:

const aliens = ["Blorgous", "Glamyx", "Wegord", "SpaceKing"];

greetAliens(aliens);

Hi there! Looks like you are using .push() incorrectly here. As you can see from this documentation on .push(), the method is used to add items into the array, not remove them. That means every time you call array.push(aliens) you are adding all the items of the array to itself again.

Try using the index i of your for loop instead. Remember that we can access items in an array by using their index position

let coolArray = ['hello', 'there', 'and','good','luck'];
console.log(coolArray[0]) // prints hello
console.log(coolArray[1]) // prints there
console.log(coolArray[2]) // prints and
...

As a final note, I think you were trying to use .pop() instead. Check this for .pop()

1 Like

Hey, a familiar name from Webdev With Sonny! Hi irlfede.

It’s fixed after I closed resetted the workspace , closed and reopend Chrome and copied the code from this post. I also finshed the the exercise and I moved on with the other code challenges.

Thank you!

1 Like