I was trying to solve this starting from the top and having it decrease. Anyone tell me what im missing?

Tell us what’s happening:
Describe your issue in detail here.

   **Your code so far**

function factorialize(num) {
let product = 1
  for (let i = num; i = 0; i--){
   product *= i
 } return product

   **Your browser information:**

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

Challenge: Factorialize a Number

Link to the challenge:

In this line, you have i = 0. What do you think that is doing? I would suggest looking up the difference between the assignment operator and comparison operators. There is a further issue with the logic there, but if you fix this here, it works.

whats the issue with logic? i just changed i === 0 and its still not working

So let’s look at how a for loop actually works:

for( starting condition; continuing condition; altering condition){

  • The starting condition in yours is i = num. So you’re saying "set my i to the value of num before looping. Works as intended, and will do exactly as you say.
  • The continuing condition means “Loop so long as this condition is being met.” In your case, you’re saying “Loop as long as i is exactly equal to 0.” But is that your intent?

thank you so much. i figured it

1 Like

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