I've written what I think should be a working solution to Project Euler 16 in JavaScript, and it tests well for small powers of 2 - but arrives at an incorrect result for 2^n where n = 1000. Here is my code:
function problem16(n) {
var prod = Math.pow(2, n);
console.log ("Prod: "+ prod);
var sum = 0;
while (prod >=1) {
console.log ("Sum term: " + prod%10);
sum += prod%10;
console.log ("Sum: "+ sum);
prod = Math.floor(prod / 10);
console.log ("Prod: "+ prod);
console.log ("------------");
}
return sum;
}
console.log("Sum is: " + problem16(1000));
Any help much appreciated.