avr39ripe

jsRectObjDraft

Feb 18th, 2021 (edited)
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <title>Study</title>
  6. </head>
  7. <body>
  8.     <script>
  9.         'use strict'
  10.  
  11.         function rectPrint(rectObj) {
  12.             console.log(`Rectangle info:`);
  13.             console.log(`leftUp(${rectObj.leftUpX}, ${rectObj.leftUpY})`);
  14.             console.log(`rightDown(${rectObj.rightDownX}, ${rectObj.rightDownY})`);
  15.         }
  16.  
  17.         function rectWidth(rectObj) {
  18.             return rectObj.rightDownX - rectObj.leftUpX;
  19.         };
  20.  
  21.         function rectHihgt(rectObj) {
  22.             return rectObj.rightDownY - rectObj.leftUpY;
  23.         };
  24.  
  25.         function rectPerimeter(rectObj) {
  26.             return rectWidth(rectObj) * 2 + rectHihgt(rectObj) * 2;
  27.         };
  28.  
  29.         function rectChangeWidth(rectObj, width) {
  30.             rectObj.rightDownX = rectObj.leftUpX + width;
  31.         };
  32.  
  33.         //let rect = { leftUp: { x: 0, y: 0 }, rightDown: { x: 10, y: 10 } };
  34.         {
  35.             let rect = { leftUpX: 0, leftUpY: 0, rightDownX: 10, rightDownY: 10 };
  36.  
  37.             let rect1 = { leftUpX: 20, leftUpY: 20, rightDownX: 45, rightDownY: 45 };
  38.             rectPrint(rect);
  39.             rectPrint(rect1);
  40.  
  41.             console.log(`rect width is: ${rectWidth(rect)}`);
  42.             console.log(`rect1 hight is: ${rectHihgt(rect1)}`);
  43.  
  44.             console.log(`rect perimetr is: ${rectPerimeter(rect)}`);
  45.             console.log(`rect1 perimetr is: ${rectPerimeter(rect1)}`);
  46.  
  47.             rectChangeWidth(rect, 20);
  48.             rectPrint(rect);
  49.             console.log(`rect width is: ${rectWidth(rect)}`);
  50.             console.log(`rect perimetr is: ${rectPerimeter(rect)}`);
  51.         }
  52.        
  53.  
  54.  
  55.     </script>
  56. </body>
  57. </html>
Add Comment
Please, Sign In to add comment