How do I push numbers in one array with a for loop

Tell us what’s happening:
Describe your issue in detail here.
what I am trying to do is push 5,4,3,2,1 into arr but instead I get
[5, 4]
[5, 4, 3]
[5, 4, 3, 2]
[5, 4, 3, 2, 1]

  **Your code so far**

function factorialize(num) {
 let arr = []
  for (let i = num; i > 0; i--) {
  return arr

  **Your browser information:**

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

Challenge: Factorialize a Number

Link to the challenge:

You are pushing 5, 4, 3, 2, 1 in though? The end result is [5,4,3,2,1], you’re just logging what the array looks like on each step as well.

Note that you don’t need to push anything into an array for this challenge, you just need to multiply numbers.

awe thanks man I was so confused I can’t believe how many hour through out the month I spent trying to figure out what was wrong.

1 Like

:confused: ah no, there was nothing wrong! So console.log just logs useful info, it doesn’t do anything apart from that. If you move the console log to just after the loop, just before the return, you’d see the end result in the console each time

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.