Advertisement
informaticage

MeatBalls problem js

Nov 17th, 2022
1,233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 2.73 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3.  
  4. <head>
  5.     <meta charset="UTF-8">
  6.     <meta http-equiv="X-UA-Compatible" content="IE=edge">
  7.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  8.     <title>Meet balls</title>
  9.  
  10.     <style>
  11.         .container .row {
  12.             display: flex;
  13.             justify-content: space-around;
  14.         }
  15.  
  16.         .circle {
  17.             border-radius: 50%;
  18.             background-color: aquamarine;
  19.             height: 1000px;
  20.             width: 1000px;
  21.         }
  22.  
  23.         .size-1 {
  24.             width: calc(30px * 1);
  25.             height: calc(30px * 1);
  26.         }
  27.  
  28.         .size-2 {
  29.             width: calc(30px * 2);
  30.             height: calc(30px * 2);
  31.         }
  32.  
  33.         .size-3 {
  34.             width: calc(30px * 3);
  35.             height: calc(30px * 3);
  36.         }
  37.  
  38.         .size-4 {
  39.             width: calc(30px * 4);
  40.             height: calc(30px * 4);
  41.         }
  42.  
  43.         .size-5 {
  44.             width: calc(30px * 5);
  45.             height: calc(30px * 5);
  46.         }
  47.  
  48.         .size-6 {
  49.             width: calc(30px * 6);
  50.             height: calc(30px * 6);
  51.         }
  52.  
  53.         .size-7 {
  54.             width: calc(30px * 7);
  55.             height: calc(30px * 7);
  56.         }
  57.  
  58.         .size-8 {
  59.             width: calc(30px * 8);
  60.             height: calc(30px * 8);
  61.         }
  62.  
  63.         .size-9 {
  64.             width: calc(30px * 9);
  65.             height: calc(30px * 9);
  66.         }
  67.  
  68.         .size-10 {
  69.             width: calc(30px * 10);
  70.             height: calc(30px * 10);
  71.         }
  72.     </style>
  73. </head>
  74.  
  75. <body>
  76.     <main class="container">
  77.         <section class="row" id="circles-container">
  78.             <!-- ** circles here ** -->
  79.         </section>
  80.     </main>
  81.  
  82.     <script>
  83.         const renderCircle = (size = false) => {
  84.             return `
  85.                 <div class="circle size-${size}"></div>
  86.             `;
  87.         }
  88.  
  89.         const generateRandom = (min, max) => {
  90.             return Math.floor(((Math.random() * (2 << 24)) % max) + min);
  91.        }
  92.  
  93.        const generatedCirclesSizes = [...Array(5)]
  94.            .map(item => (
  95.                 generateRandom(1, 10)
  96.             ));
  97.  
  98.         function renderCircles(doSorting) {
  99.             if (doSorting) {
  100.                 generatedCirclesSizes.sort((a, b) => a - b);
  101.             }
  102.  
  103.             const generatedCircles = generatedCirclesSizes.map(renderCircle);
  104.  
  105.             // console.log(generatedCircles);
  106.  
  107.             const circlesContainer = document
  108.                 .querySelector("#circles-container")
  109.                 .innerHTML = generatedCircles.join("");
  110.         }
  111.  
  112.         renderCircles();
  113.     </script>
  114.  
  115.     <button onclick="renderCircles(true)">Sort me</button>
  116. </body>
  117.  
  118. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement