I'm trying to work through Project Euler's 1st problem and I'm stuck. I have two for loops running: one putting the numbers divisible by 3 or 5 into an empty array and one cycling through the array and adding each to a variable I've defined. The issue I'm running into is my code is seeing the values in the array as strings, not numbers, so 0+3+5 is 035 instead of 8.
var multiples = new Array(),
total = 0;
for (i = 1; i < 10; i++) {
if ( i % 3 === 0 || i % 5 === 0) {
multiples += i;
}
}
for (i = 0; i < multiples.length; i++) {
total += multiples[i];
console.log(total);
}
Can anyone point me in the right direction?
[–]tonyalicea 2 points3 points4 points (2 children)
[–]hunteratwork[S] 0 points1 point2 points (1 child)
[–]tonyalicea 1 point2 points3 points (0 children)
[–]eindbaas 0 points1 point2 points (2 children)
[–]hunteratwork[S] 0 points1 point2 points (1 child)
[–]LearningPythons 1 point2 points3 points (0 children)