Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <script>
- function Rectangle(widht, height){
- this.widht =widht;
- this.height = height;
- }
- Rectangle.prototype.PrintRectangle = function(){
- return "Rectangle width is: " + this.widht + " and rectangle height is: "+ this.height;
- }
- Rectangle.prototype.RectanglePerimetar = function(){
- return this.widht * this.height
- };
- var prvPrav = new Rectangle(2,4)
- var vtorPrav = new Rectangle(8.5,11)
- rectArr =[prvPrav, vtorPrav]
- function naLoad(){
- for(var i = 0; i<rectArr.length; i++){
- var node1 = document.createElement("p")
- var textNode1 = document.createTextNode(rectArr[i].PrintRectangle())
- node1.appendChild(textNode1)
- document.getElementById("paragraf1").appendChild(node1)
- }
- }
- function calculate(){
- var max = 0;
- for(var i =0; i<rectArr.length; i++){
- console.log(rectArr[i].RectanglePerimetar())
- if(rectArr[i].RectanglePerimetar() > max){
- max = rectArr[i].RectanglePerimetar()
- }
- }
- console.log(max)
- document.getElementById("paragraf2").innerHTML = "The biggest Rectangle has a perimeter of: " + max
- }
- </script>
- </head>
- <body onload="naLoad()">
- <p style="font-weight: bold;">Paragraph no: 1</p>
- <div id="paragraf1">
- </div>
- <p style="font-weight: bold;">Paragraph no: 2</p>
- <div id="paragraf2">
- </div>
- <br />
- <button onclick="calculate()">Calculate Perimetar</button>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement