Skip to content
Advertisement

Fill array with prompt in JavaScript and use push method

I am learning arrays in JavaScript and I am using the foreach with the push method.

The following code is working as its supposed to:

JavaScript

But I want to replicate this with a prompt, instead of hard coding the values in the array. And end the prompt with a 0. The code I attempted is the following, but the variables pos and neg are never evaluated’, this is my code:

JavaScript

What have I done wrong in my code?

Advertisement

Answer

You need to push the number into numbers array

JavaScript

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement