Question: var items = [one, 32, true, two, 33.1, 45, world, false]; program in JS that gives the total of summation for numbers only. In this
var items = ["one", 32, true, "two", 33.1, 45, "world", false];
program in JS that gives the total of summation for numbers only.
In this case, it will add only 32, 33.1 and 45 as an example and should not try to add when it gets non numeric item.
Hint:
var total = 0;
for (var i = 0 ; i < items.length ; i++) {
if (typeof items[i] === 'number') {
//your code here to accumulate the summation on total
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
