Javascript Project : Factorial - Do While - While Loops


SUBMITTED BY: Guest

DATE: Dec. 29, 2013, 11:46 p.m.

FORMAT: Text only

SIZE: 735 Bytes

HITS: 1291

  1. var dwinteger=1;
  2. var dwtotal=0;
  3. do
  4. {
  5. dwinteger=dwinteger+2;
  6. dwtotal=dwtotal+dwinteger;
  7. }
  8. while (dwinteger<=99);
  9. var winteger=1;
  10. var wtotal=0;
  11. while (winteger<=100)
  12. {
  13. winteger=winteger+1;
  14. wtotal=wtotal+winteger
  15. }
  16. function factorial()
  17. {
  18. var f_input=prompt("Calculate the factorial of:");
  19. var total=1;
  20. var counter=1;
  21. for (counter=1;counter<=f_input;counter++)
  22. {
  23. total=total*counter;
  24. }
  25. alert("Factorial " + f_input + ": " + total + '\n' + '\n' + '\n' +
  26. "Do - While loop: Sum of all odd numbers from: 1-100: " + dwtotal + '\n' + '\n' + '\n' + "While loop: Sum of all numbers from: 1-100: " + wtotal);
  27. }

comments powered by Disqus