I saw a bunch of other posts on this topic but none in javascript. here is my code.
var theNumber = function digitAdd (base, exponent) {
var number = 1;
for (i=0; i < exponent; i++) {
var number = base * number;
}
return number
}
function find(theNumber) {
var sum=0;
parseInt(theNumber);
while(theNumber>0)
{
sum=sum+theNumber%10;
theNumber=Math.floor(theNumber/10);
}
document.writeln(Sum of digits +sum);
}
find(theNumber (2, 50));
I am getting the correct answer, I just don't fully understand the 2nd function, namely the while statement. Any help would be greatly appreciated. Thanks!