Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.Start your free trial
Scott Rushford1,724 Points
Cannot find issue with function for iterating array numbers, adding them, evaluating, and returning largest index.
In this code, I have been able to get to where all items in the array are able to be utilized individually, but I cannot seem to get them to add and evaluate. It appears I am only returning the first number of the array in each sequence. I tried to put many console.log markers to walk it through, but I am baffled.
The goal is to return the actual credit card number with the highest sum of all its digits. Two are the same, but the code must return the most recent. Any ideas to what I am missing?
Steven Parker228,978 Points
The final log statement is attempting to print an internal variable of the maxCardSum function, maybe it was originally inside the function and moved? But now you can capture the returned value and display that instead:
var max = maxCardSum(cards); // capture the returned value in "max"
console.log("The credit card number with the max sum of all numbers is: " + max);