63 067
Assignments Done
99,1%
Successfully Done
In July 2018

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
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)
}

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 first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions