Advertisement
Guest User

Sims JS

a guest
Nov 12th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <script>
  5.  
  6. function Rectangle(widht, height){
  7. this.widht =widht;
  8. this.height = height;
  9. }
  10.  
  11. Rectangle.prototype.PrintRectangle = function(){
  12. return "Rectangle width is: " + this.widht + " and rectangle height is: "+ this.height;
  13. }
  14. Rectangle.prototype.RectanglePerimetar = function(){
  15. return this.widht * this.height
  16. };
  17.  
  18. var prvPrav = new Rectangle(2,4)
  19. var vtorPrav = new Rectangle(8.5,11)
  20.  
  21.  
  22. rectArr =[prvPrav, vtorPrav]
  23.  
  24.  
  25.  
  26. function naLoad(){
  27.  
  28. for(var i = 0; i<rectArr.length; i++){
  29. var node1 = document.createElement("p")
  30. var textNode1 = document.createTextNode(rectArr[i].PrintRectangle())
  31. node1.appendChild(textNode1)
  32.  
  33. document.getElementById("paragraf1").appendChild(node1)
  34. }
  35. }
  36.  
  37.  
  38. function calculate(){
  39.  
  40. var max = 0;
  41. for(var i =0; i<rectArr.length; i++){
  42. console.log(rectArr[i].RectanglePerimetar())
  43. if(rectArr[i].RectanglePerimetar() > max){
  44. max = rectArr[i].RectanglePerimetar()
  45. }
  46. }
  47. console.log(max)
  48. document.getElementById("paragraf2").innerHTML = "The biggest Rectangle has a perimeter of: " + max
  49. }
  50.  
  51.  
  52. </script>
  53. </head>
  54. <body onload="naLoad()">
  55.  
  56.  
  57.  
  58.  
  59. <p style="font-weight: bold;">Paragraph no: 1</p>
  60. <div id="paragraf1">
  61.  
  62. </div>
  63. <p style="font-weight: bold;">Paragraph no: 2</p>
  64. <div id="paragraf2">
  65.  
  66. </div>
  67. <br />
  68. <button onclick="calculate()">Calculate Perimetar</button>
  69.  
  70.  
  71. </body>
  72. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement