Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


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

Explain few difference between null, undefined or undeclared javascript variable?

1 Answers  


What is lazy loading in javascript?

1 Answers  


how to validate the date(dd/mm/yyyy)using regular expression in javascript? It should also satisfy the leap year feb 29 problem. Please help me.

2 Answers  


List few difference between primitive and non primitive javascript data types?

1 Answers  


What is the difference between typeof and instanceof operators in Javascript?

1 Answers  


Is there an ide for javascript?

1 Answers  


What causes memory leaks?

1 Answers  


Is javascript harmful?

1 Answers  


What is an empty html tag?

1 Answers  


What is the data type of variables in javascript?

1 Answers  


Why do we need npm?

1 Answers  


What is the difference between the operators '==' and '==='?

1 Answers  


Categories