javascript - Recursion "maximum call stack size exceeded" - decimal to hexadecimal converter -


i'm trying make decimal hexadecimal converter without using number.prototype.tostring (this assignment not allow function). attempting use recursion try work it. works until else inside main else if makes sense. gives me error when run number above 255 (i.e. number has more 2 digits in hexadecimal). know why case?

var number = parseint(prompt("give me number , turn hexadecimal!")); var digit = 1; var hexconverter = function () {     if (digit === 1) {         if (math.floor(number / 16) === 0) {             console.log(hexdigits[number]);         } else {             digit = 16;             console.log(hexconverter(), hexdigits[number % 16]);         }     } else {         if (math.floor(number / (digit * 16)) === 0) {             return (hexdigits[math.floor(number / digit)]);         } else {             return (hexconverter(), hexdigits[number % (digit * 16)]);         }         digit = digit * 16;     } }; hexconverter(); 

you changing digit after making recursive call, stuck @ 16 , never point increase it.

move digit = digit*16; before recursive call, have digit = 16 in first part.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -

php - Accessing static methods using newly created $obj or using class Name -