math - factorial in javascript. Doesn't work -


here script, don't understand why doesn't work...

function firstfactorial(num) {  var lower = num - 1; var qq = 0;  while (num > 0) { var qq === num * lower; num--; lower--; } num === qq; return num; } firstfactorial(num); 

you have quite few issues function, see comments.

function firstfactorial(num) {     var lower = num - 1;     var qq = 0;      while (num > 0) {         // here shadowing "qq" variable in outer scope         // delete "var" keyword fix         // === identity operator, think wanted assignment (=)         // line becomes: qq = num * lower;         var qq === num * lower;         num--;         lower--;     }      // assuming === supposed = again     // can rewrite just: return qq;     num === qq;     return num; }  firstfactorial(num); 

even these syntactical fixes, logic calculating factorial not correct.

edit: working examples (because bored) http://jsfiddle.net/gu2cz/


Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

javascript - Preserving URL fragment through CAS sign-on -

asp.net mvc - Implementing normal user/pass, Twitter & Facebook auth -