You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The HTML for the graph is generated by the code in index.js. You don't need to worry about how the code works (unless
you want to!).
The graph has 7 squares in each column, representing each day of the week, and 52 squares in each row, representing
each week of the year.
Style the graph whit default squares. then create selectors that will style each square based on the number of
contributions per day. The JS code randomly each square a contribution level of 0, 3, 5, or 10, which is assigned
using a data property. The lighter the color, the greater the number of contributions for the day.
Hints
This challenge is a really great candidate for CSS grid and the repeat() function.
For styling the squares, look int using attribute selectors.
functiongenerateRandomContributionStats(){constcontributions=[];constlevels=[0,0,0,3,5,10];for(leti=0;i<52;i++){constweek=[];// make 7 squares and randomlyfor(leti=0;i<7;i++){week.push(levels[Math.floor(Math.random()*levels.length)]);}contributions.push(week);}returncontributions;}functionmakeGraph(){constgraph=document.querySelector(".graph");constcontributions=generateRandomContributionStats();for(leti=0;i<contributions.length;i++){//Create a li for each week and add to graph ulletgraphWeek=document.createElement("ul");graphWeek.classList.add(`week-${i+1}`);//Create a square for each contribution array, and assign a levelcontributions[i].forEach((level)=>{letsquare=document.createElement("li");square.classList.add("square");square.dataset.value=level;graphWeek.appendChild(square);graph.appendChild(graphWeek);});}}makeGraph();