MCPcopy Create free account
hub / github.com/Vishal-raj-1/Awesome-JavaScript-Projects / generatebars

Function generatebars

assets/js/selectionsort.js:4–39  ·  view source on GitHub ↗
(num = 20)

Source from the content-addressed store, hash-verified

2
3// function to generate bars
4function generatebars(num = 20) {
5
6 //for loop to generate 20 bars
7 for (let i = 0; i < num; i += 1) {
8
9 // To generate random values from 1 to 100
10 const value = Math.floor(Math.random() * 100) + 1;
11
12 // To create element "div"
13 const bar = document.createElement("div");
14
15 // To add class "bar" to "div"
16 bar.classList.add("bar");
17
18 // Provide height to the bar
19 bar.style.height = `${value * 3}px`;
20
21 // Translate the bar towards positive X axis
22 bar.style.transform = `translateX(${i * 30}px)`;
23
24 // To create element "label"
25 const barLabel = document.createElement("label");
26
27 // To add class "bar_id" to "label"
28 barLabel.classList.add("bar_id");
29
30 // Assign value to "label"
31 barLabel.innerHTML = value;
32
33 // Append "Label" to "div"
34 bar.appendChild(barLabel);
35
36 // Append "div" to "data-container div"
37 container.appendChild(bar);
38 }
39}
40
41// asynchronous function to perform "Selection Sort"
42async function SelectionSort(delay = 300) {

Callers 1

selectionsort.jsFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected