I’m trying to create a function that takes an integer input, adds each digit together, and if there are more than 1 digit, then do it again and again until there is only one.
Input = 456
~ 1+5 = 6
so the function would return 6.
My algorithm seems to work, as tested by alert() messages, but somehow at the final step of returning the value, everything falls apart.
The solution seems so simple that I literately ran out of ideas to even test why it doesn’t work. Please help.
I put the two questions I have as comments in the JSFiddle code, here’s the link:
Thanks in advance