Created
June 8, 2018 18:46
-
-
Save willeswa/69bdeb784c8b2fb9e315ed87397b41d9 to your computer and use it in GitHub Desktop.
bKByov
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var num = prompt("Give number"); | |
function fact(num) { | |
var fact; | |
while(num>0){ | |
fact *= num--; | |
num--; | |
} | |
return fact; | |
} | |
alert("Factorial is: "+fact(num)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Line 5 needs to be
var fact = 1;
so you don't start by multiplying by 0
Line 8 needs to be
fact *= num;
so you are multiplying "fact" by the current counter BEFORE you decrement "num" by 1