What is missing in my code?
function numberTally(numList) {
var evenTotal = 0;
var oddTotal = 0;
for (var i = 0; i <= numList.length; i++) {
if i % 2 { // i is odd
oddTotal += numList[i];
// or oddTotal = oddTotal +
numList[i];
}
else { // i is even
evenTotal + numList[i];
}
}
alert(oddTotal);
return evenTotal;
}
Answer / Pankaj Kumar Dagar
In your JavaScript function, you are missing the following lines to calculate the sum of even and odd numbers separately:
```javascript
for (var i = 0; i <= numList.length - 1; i++) {
if (numList[i] % 2 === 0) {
evenTotal += numList[i];
} else {
oddTotal += numList[i];
}
}
alert(evenTotal + ' and ' + oddTotal);
```
| Is This Answer Correct ? | 0 Yes | 0 No |
How do I open a website code?
How to create an object using javascript?
Enumerate the differences between Java and JavaScript?
Describe javascript and vbscript.
can wwe trace a java program (class)
What's the Difference Between Class and Prototypal Inheritance?
What coding language should I learn first?
what is eval pls breif information send me
Is javascript default scripting language?
why we use javascript in html ?
What is Unobtrusive JavaScript & Why it's Important?
Where do you write javascript?