August 2nd, 2024
What's missing in this code?
// get the product of the sum of number digits
// until you get to a single digit, or before the product
// becomes zero
// productOfSum(32, 87); // -> 119 -> 9
// productOfSum(382, 234); // 616 -> 36 -> 18
// productOfSum(5123, 3774); // 8897 -> 4032 (stop before 0)
function productOfSum(num1, num2)
let product = num1 + num2;
while (product
10)
const newProduct = product
.
.split('')
.reduce((prod, digit) => prod * Number(digit),
);
if (newProduct ===
) break;
product = newProduct;
}
return product;
}
Type or select from these options