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
1
Expert's answer
2013-11-21T11:47:17-0500
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)
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS