你有相当这个功能很少出现问题,请参阅评论。
function FirstFactorial(num) {
var lower = num - 1;
var qq = 0;
while (num > 0) {
// here you are shadowing the "qq" variable in the outer scope
// delete the "var" keyword to fix this
// also === is an identity operator, i think you wanted assignment (=)
// so this line becomes: qq = num * lower;
var qq === num * lower;
num--;
lower--;
}
// assuming that === was supposed to be = again
// you can rewrite this as just: return qq;
num === qq;
return num;
}
FirstFactorial(num);
即使有了这些语法修正,您的逻辑计算阶乘是不正确的。编辑:工作例子(因为我很无聊)http://jsfiddle.net/gU2cz/