# Answer to Question #37167 in Java | JSP | JSF for Richard

Question #37167

Language is javascript.

Heres the question -

Write a program that loops one thousand times. Add all the even numbers and display the results. Add all the odd numbers and display the results.

Sample output -

Even Total: 249500

Odd Total: 250000

Heres the question -

Write a program that loops one thousand times. Add all the even numbers and display the results. Add all the odd numbers and display the results.

Sample output -

Even Total: 249500

Odd Total: 250000

Expert's answer

window.onload = function() {var loop = 1000, //loop times

even_total = 0, //even nums sum

odd_total = 0, // odd nums sum

i = 0; //counter

do {

if (i % 2 == 0) {

even_total+=i;

} else {

odd_total+=i;

}

} while (i++ < loop);

console.log('even total = ' + even_total);

console.log('odd total = ' + odd_total)

}

even_total = 0, //even nums sum

odd_total = 0, // odd nums sum

i = 0; //counter

do {

if (i % 2 == 0) {

even_total+=i;

} else {

odd_total+=i;

}

} while (i++ < loop);

console.log('even total = ' + even_total);

console.log('odd total = ' + odd_total)

}

## Comments

## Leave a comment