I'm trying to make a program that will take the digits in a number and multiply them with each other. So 583
would be 5*8*3 = 120
.
Its not working as intended, its just returning the number
that was put in.
How can I fix it?
Here's the code:
function persistence(num) {
//code me
numString = num.toString();
numArray = numString.split().map(function(t) {
return parseInt(t)
});
function reducer(theNumArray) {
let sum = 1;
for (var i = 0; i < theNumArray.length; i++) {
sum = sum * theNumArray[i];
}
return sum;
}
newNum = reducer(numArray);
console.log(newNum);
};
persistence(485);