1
I have a piece of code that calculates the factorial of a number in Javascript, but I wanted it to return the steps of each calculation, ex:
3! = 1x2x3 = 6
Follow the code I made. I tried "printar" by decreasing the variable, but I’m not sure what I’m doing.
var fatorial=1;
var num=parseInt(prompt("Digite um número: "));
for(var x=1; x<=num; x++)
{
fatorial=fatorial*x;
}
document.write(num+"! = "+num+"x"+(num--)+"="+fatorial);
Did any of the answers solve your question? Do you think you can accept one of them? Check out the [tour] how to do this, if you haven’t already. You would help the community by identifying what was the best solution for you. You can accept only one of them. But you can vote on any question or answer you find useful on the entire site (when you have enough score).
– Maniero