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;

}



What is missing in my code? function numberTally(numList) { var evenTotal = 0; var oddTotal ..

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

Post New Answer

More JavaScript Interview Questions

How do I open a website code?

1 Answers  


How to create an object using javascript?

1 Answers  


Enumerate the differences between Java and JavaScript?

1 Answers  


Describe javascript and vbscript.

1 Answers  


can wwe trace a java program (class)

1 Answers   CMC,


What's the Difference Between Class and Prototypal Inheritance?

1 Answers  


What coding language should I learn first?

1 Answers  


what is eval pls breif information send me

1 Answers  


Is javascript default scripting language?

1 Answers  


why we use javascript in html ?

4 Answers  


What is Unobtrusive JavaScript & Why it's Important?

1 Answers  


Where do you write javascript?

1 Answers  


Categories