Advertisement
Guest User

Untitled

a guest
May 28th, 2015
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.77 KB | None | 0 0
  1.  
  2. function execCode() {
  3. heading();
  4. year();
  5.  
  6.  
  7. }
  8.  
  9. function heading() {
  10. println(" Amount Amount");
  11. println(" Simple Compound");
  12. println("Year Interest Interest");
  13. }
  14.  
  15.  
  16. function year() {
  17. for (var i = 1; i < 10; i++) {
  18. var yr = i;
  19. var smpl = 1000+(50*i);
  20.  
  21.  
  22. print(yr);
  23. print(" ");
  24. print("$"+smpl+".00");
  25. print(" ");
  26.  
  27. switch (i) {
  28. case 1:
  29. var a = 1000*1.05;
  30. println(a);
  31. break;
  32.  
  33. case 2:
  34. var b = newRound(a*1.05,2);
  35. println(b);
  36. break;
  37.  
  38. case 3:
  39. var c = newRound(b*1.05,2);
  40. println(c);
  41. break;
  42.  
  43. case 4:
  44. var d = newRound(c*1.05,2);
  45. println(d);
  46. break;
  47.  
  48. case 5:
  49. var e = newRound(d*1.05,2);
  50. println(e);
  51. break;
  52.  
  53. case 6:
  54. var f = newRound(e*1.05,2);
  55. println(f);
  56. break;
  57.  
  58. case 7:
  59. var g = newRound(f*1.05,2);
  60. println(g);
  61. break;
  62.  
  63. case 8:
  64. var h = newRound(g*1.05,2);
  65. println(h);
  66. break;
  67.  
  68. case 9:
  69. var j = newRound(h*1.05,2);
  70. println(j);
  71. break;
  72. }
  73.  
  74. }
  75. }
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84. // Return the HTML element named 'id'
  85. function getElement(id) {
  86. return document.getElementById(id);
  87. }
  88.  
  89. // Return the text in the 'Input:' box
  90. function getInput() {
  91. var input = getElement("input");
  92. return input.value;
  93. }
  94.  
  95. // Print to the 'output' HTML element
  96. function print(x) {
  97. var out = getElement("output");
  98. out.value = out.value + x;
  99. }
  100.  
  101. // Clear the 'output' text area
  102. function clr() {
  103. //alert("hey");
  104. var out = getElement("output");
  105. out.value = "";
  106. }
  107.  
  108. // Print to the 'output' HTML element and
  109. // add the line end
  110. function println(x) {
  111. if (x === undefined) {
  112. x = "";
  113. }
  114. print(x + '\n');
  115. }
  116.  
  117. // Sample using the canvas to draw on
  118. function drawExample() {
  119. var c;
  120. var cx;
  121. c = getElement("drawing");
  122. cx = c.getContext("2d");
  123. //cx.strokeStyle = "red";
  124. cx.lineWidth = 1;
  125. // draw rect with narrow lines
  126. cx.strokeRect(5, 5, 100, 50);
  127. // draw rect with wider lines
  128. cx.strokeStyle = "red";
  129. cx.lineWidth = 5;
  130. cx.strokeRect(135, 5, 50, 50);
  131.  
  132. }
  133.  
  134. // User defined round function
  135. // Pass in the number and the number of
  136. // decimal places to retain
  137. function newRound(num, places) {
  138. tens = Math.pow(10, places);
  139. var temp = num * tens;
  140. temp = Math.round(temp);
  141. temp = temp / tens;
  142. return temp;
  143. }
  144.  
  145. // Put code here to execute when the user
  146. // presses the 'Run Program' button
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement