I am trying to take an array of numbers and log what numbers are modulus 2 with a remainder of 0 i % 2 === 0. For the numbers that are modulus 2 with a remainder of 1 i % 2 === 1, I want to push those numbers to an array (seemed like the best fit to log a set of numbers).
From there I would return the sumTotal of the numbers that are %2 === 0 and print which numbers in the array were %2 === 1.
The problem below works for the if statement but when I added in my else if I am having trouble figuring out how to push items into the array in the else if statement.
var numSet = [1, 4, 6, 450, 5, 222, 397, 962, 678, 222, 459];
var myFunc = function (num) {
var total = 0;
var total2 = [];
for (var i = 0; i < num.length; i += 1) {
if (num[i] % 2 === 0) {
total += num[i];
} else if (num[i] % 2 === 1) {
total2[num[i]] = num[i].push;
console.log(total2);
}
}
return 'The total is ' + total + ' and the remainder is ' + total2;
};
total2.push(num[i])