I was wondering how I could return these two values (totalPositive and newArr) in the same function. I want to return the array and then modify it (add all the values together and return that value). Here’s my code:
function sumDigits(num) {
var newArr = []
var stringifiedNum = num.toString()
for (var i = 0; i < stringifiedNum.length; i++) {
newArr.push(stringifiedNum[i])
}
return newArr
var totalPositive = 0
for (var i = 0; i < newArr.length; i++) {
totalPositive += newArr[i]
}
// return totalPositive?
}
var outputPositive = sumDigits(1148);
console.log(outputPositive); // --> 14