0

Factorial Problem in JavaScript

A factorial problem in JavaScript If the input number is 4, I got answer like 4 12 24 24 The answer should be just 24. What should I change in the code? My code is below. function main() { var number = parseInt(readLine(), 10) var factorial = 1; for(number ; number >= 1 ; number-- ) { factorial = factorial * number console.log(factorial) } // Your code here }

2nd Jun 2021, 1:07 PM
Rani Go
Rani Go - avatar
3 Answers
+ 3
Print output after for loop.. (put console.log(factorial) outside loop, not within loop...)
2nd Jun 2021, 1:18 PM
Jayakrishna 🇼🇳
+ 1
Got it!! Thank you!
2nd Jun 2021, 1:22 PM
Rani Go
Rani Go - avatar
0
You're welcome...
2nd Jun 2021, 1:22 PM
Jayakrishna 🇼🇳