0
I cant make Factorial task
Factorial of number 5 is (5*4*3*2*1) understand? So, i have my premium task, to make factorial by the function “for” with loops. I cant understand how to make it right because every try is all wrong or some tests are right but not all.
7 odpowiedzi
+ 11
Alex , you are right saying that factorial of 5 is 5*4*3*2*1.
- to calculate it, you need a for loop. i think you are familiar with that.
- so use the for loop combined with a range object that contains all numbers you need (1...5) or (2...5 - as multiplying with 1 does not change anything).
- so you just have to make a variable that holds the current product, and update it in each loop iteration.
that's all.
+ 10
Alex as Denise Roßberg suggested 👍
If you need help, you can post the code you're struggling with. Try to search for similar questions or answers before posting.
• https://www.sololearn.com/post/75089/?ref=app
+ 10
Alex
I hope that based on these examples you will get an idea and succeed in solving your task.👍
• https://code.sololearn.com/WMt3NCSb4mrO/?ref=app
+ 9
Hello Alex
can you please share your code so that we can see what went wrong?
+ 7
You need to store the value of factorial.
Here are some possibilities how to solve this task: https://www.google.com/amp/s/www.freecodecamp.org/news/how-to-factorialize-a-number-in-javascript-9263c89a4b38/amp/
+ 1
process.stdin.setEncoding('utf-8');
let inputString = '';
process.stdin.on('data', inputStdin => {
inputString += inputStdin;
});
process.stdin.on('end', _ => {
main(inputString);
});
function main(input) {
var number = parseInt(input, 10)
var factorial = number - 1;
for (idk what to write)
console.log(number * factorial--)
}
Denise Roßberg
0
Lothar in case all is simple i used to use “for” for looping but i cant make the correct loop