Advertisement
Guest User

Untitled

a guest
Apr 1st, 2020
368
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.18 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <!-- Lawrence Lin Section 32-->
  5. <meta charset = "UTF-8" />
  6. <title> Exam2-Part4 </title>
  7. <style>
  8. body {background-color: lightskyblue; font-family: optima;
  9. color: maroon; text-align: center}
  10. p { font-size: 20px}
  11. button {font-size: 20px; background-color: coral}
  12. input { font-size: 20px;text-align: center}
  13. </style>
  14. </head>
  15.  
  16. <script>
  17. var paintCost = 0; //total cost for the painting
  18. var ductCost = 0 //total cost for the heating duct work
  19. var floorCost = 0; //total cost for the oak flooring
  20. var smartCost = 0; //total cost for the smart home devices
  21. var devices = new Array(); //array to hold the number of devices in each room
  22.  
  23. /*
  24. This function calculates and returns the total cost of the paint job as described in the .pdf file.
  25. The parameter rooms is the number of rooms to be painted. You can assume rooms >= 0.
  26. The parameter thirdCoat has either the value 'yes' or the value 'no'.
  27. */
  28. function calculatePaintCost(rooms, thirdCoat){
  29.  
  30. paintCost = 300 * rooms;
  31.  
  32. if (thirdCoat == 'yes'){
  33.  
  34. paintCost = (paintCost * 0.3) + paintCost;
  35.  
  36. }
  37.  
  38.  
  39. return paintCost;
  40. }
  41. /*
  42. This function calculates and returns the total cost of the heating duct work and is cvalculated as
  43. described in the .pdf file.
  44. The parameter length is the length of one side of the room. You can assume length >= 0.
  45. The parameter width is the width of the adjacecent side of the room. You can assume width >= 0.
  46. The parameter shortcut has either the value 'yes' or the value 'no' and indicates whether
  47. or not the customer wants to "cut corners". The calculatations are described in the .pdf file.
  48. */
  49. function calculateDuctCost(length,width,shortcut){
  50.  
  51. return 0;
  52. }
  53.  
  54. /*
  55. This function calculates and returns the total cost of installing oak flooring as described in the .pdf file.
  56. The parameter feet is the number of square feet of oak flooring to be installed. You can assume feet >= 0.
  57. */
  58. function calculateFloorCost(feet){
  59.  
  60. if (feet < 1000){
  61. floorCost = feet * 8;
  62. }
  63. else if (feet < 1500){
  64. floorCost = feet * 7;
  65. }
  66. else if(feet < 2500){
  67. floorCost = feet * 6;
  68. }
  69. else{
  70. floorCost = feet * 4;
  71. }
  72.  
  73. return floorCost;
  74. }
  75.  
  76. function calculateSmartCost(rooms){
  77. return 0;
  78.  
  79. }
  80.  
  81. /*********************************************************************************/
  82. /* YOU DO NOT HAVE TO LOOK AT OR MODIFY ANYTHING BELOW !!! */
  83. /*********************************************************************************/
  84.  
  85. function printSmartInfo(){
  86. var s = "";
  87. for (var i = 0; i < devices.length; i++){
  88. s = s + "Rm " + (i+1) + ": " + devices[i] + " device(s) ";
  89. }
  90. return s;
  91. }
  92.  
  93. function calculateTotal(){
  94. return paintCost + ductCost + floorCost + smartCost;
  95. }
  96.  
  97.  
  98.  
  99. </script>
  100.  
  101. <body>
  102.  
  103. <h2> Painting</h2>
  104. <p>How many rooms?
  105. <input type = "text" id = "rooms" size = "10" value = "" onchange="numRooms = Number(value);" />
  106. </p>
  107. <p> Do you want a third coat?
  108. <input type = "radio" id = "yes3" name = "coats" value = ""
  109. onclick = "
  110. paintCost = calculatePaintCost(numRooms,'yes');
  111. costOfPaint.value = '$' + paintCost.toFixed(2);
  112. "> YES
  113. <input type = "radio" id = "no3" name = "coats" value = ""
  114. onclick = "
  115. paintCost = calculatePaintCost(numRooms,'no');
  116. costOfPaint.value = '$' + paintCost.toFixed(2);
  117. "> NO
  118. </p>
  119.  
  120. <p>
  121. Paint Cost <input type = "text" id = "costOfPaint" size = "10" value = "" readonly/>
  122. </p>
  123.  
  124. <h2> Heating Duct Work</h2>
  125. <p>Length of room?
  126. <input type = "text" id = "roomL" size = "10" value = "" onchange=" roomL = Number(value); " />
  127. &nbsp Width of room?
  128. <input type = "text" id = "roomW" size = "10" value = "" onchange= "roomW = Number(value); " />
  129. </p>
  130. <p> If possible, do you want diagonal duct work?
  131. <input type = "radio" id = "yes3d" name = "ducts" value = ""
  132. onclick = "
  133. ductCost = calculateDuctCost(roomL, roomW,'yes');
  134. costOfDuct.value = '$' + (ductCost).toFixed(2);
  135. "> YES
  136. <input type = "radio" id = "no3d" name = "ducts" value = "" onclick = "
  137. ductCost = calculateDuctCost(roomL, roomW,'no');
  138. costOfDuct.value = '$' + (ductCost).toFixed(2);
  139. "> NO
  140. </p>
  141. <p>
  142. Cost of Duct Work <input type = "text" id = "costOfDuct" size = "10" value = "" readonly/>
  143. </p>
  144.  
  145.  
  146. <h2> Oak Flooring</h2>
  147. <p>Enter the number of square feet you wish to cover with Oak Flooring:
  148.  
  149. <input type = "text" id = "rooms" size = "10" value = "" onchange="
  150. sqFeet = Number(value);
  151. floorCost = calculateFloorCost(sqFeet)
  152. costOfFloor.value = '$' + floorCost.toFixed(2);" />
  153. <p>
  154. Your flooring cost is: <input type = "text" id = "costOfFloor" size = "10" value = "" readonly/>
  155. </p>
  156.  
  157. <h2>Smart Home Devices </h2>
  158. <p>Enter the number of smart rooms you would like:
  159. <input type = "text" id = "srooms" size = "10" value = "" onchange="
  160. var smartRooms = Number(value);
  161. smartCost = calculateSmartCost(smartRooms);
  162. costOfSmart.value = '$' + smartCost.toFixed(2);
  163. smartInfo.value = printSmartInfo(devices);
  164. " />
  165. <p> The number of devices in each of your rooms is:<br>
  166. <input type = "text" id = "smartInfo" size = "100" value = "" readonly />
  167. </p>
  168.  
  169. <p>
  170. The cost of your smart devices is: <input type = "text" id = "costOfSmart" size = "10" value = "" readonly/>
  171.  
  172. </p>
  173.  
  174. <p>
  175. <button onclick= "totalCost.value = '$' + (calculateTotal()).toFixed(2); " Calcuate Total is:>Calculate Total</button>
  176. <input type = "text" id = "totalCost" size = "10" value = "" readonly />
  177. </p>
  178.  
  179. </body>
  180. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement