-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
31 lines (31 loc) · 1.01 KB
/
index.js
File metadata and controls
31 lines (31 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
function generateRandomContributionStats() {
const contributions = [];
const levels = [0, 0, 0, 3, 5, 10];
for (let i = 0; i < 52; i++) {
const week = [];
// make 7 squares and randomly
for (let i = 0; i < 7; i++) {
week.push(levels[Math.floor(Math.random() * levels.length)]);
}
contributions.push(week);
}
return contributions;
}
function makeGraph() {
const graph = document.querySelector(".graph");
const contributions = generateRandomContributionStats();
for (let i = 0; i < contributions.length; i++) {
//Create a li for each week and add to graph ul
let graphWeek = document.createElement("ul");
graphWeek.classList.add(`week-${i + 1}`);
//Create a square for each contribution array, and assign a level
contributions[i].forEach((level) => {
let square = document.createElement("li");
square.classList.add("square");
square.dataset.value = level;
graphWeek.appendChild(square);
graph.appendChild(graphWeek);
});
}
}
makeGraph();