Good evening people! i am in serious need of help here,I have been trying this algorithm and i can’t seem to get it right. Can someone please tell me what is wrong with my code.
please please please Your help would be greatly appreciated
here is it!!
function factorialize(num) {
var counter =0;
for(let i=1; i<=num; i++){
i *= counter;
}
return counter;
}
// function factorialize(num) {
// return num;
// }
factorialize(5);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36.
I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.
You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.
Right, that solves one problem, the other problem is still here:
for(let i=1; i<=num; i++){
i *= counter;
}
The variable i is your loop control variable - you have to be very careful messing with those in an active loop. It this case, it creates and infinite loop. But that’s OK, because that line needs to be changed anyway.
When I make those two changes, the code works.
Also, please don’t change code/text in previous posts in the thread - it creates confusion for people that try to read the thread later.