- script.js
JavaScript
var expectedUsers = 1000;
var usersByDay = [817, 1370, 752, 1247, 681, 1120, 915, 1281, 875, 1341, 757, 610, 812, 1170, 769, 1261, 845, 1289, 515, 1247, 845, 1311, 741, 1239, 812, 638, 877, 1242, 1159, 1372];
// Drawing the traffic graph
muffin.plot(usersByDay, expectedUsers);
// Summarizing traffic and analyzing the dips
var totalUsers = 0;
var minUsers = expectedUsers - 100;
for (var i = 0; i <= usersByDay.length - 1; i++) {
totalUsers += usersByDay[i];
if (usersByDay[i] < minUsers) {
console.log(usersByDay[i]);
}
}
// Calculating the average traffic value
var averageUsers = totalUsers / usersByDay.length;
console.log('Average traffic: ' + averageUsers);
if (averageUsers > expectedUsers) {
console.log('Traffic is amazing. Keep up the good work!');
} else {
console.log('Traffic is so-so. You need to try harder!');
}
Result
Goalscompleted
- After the variable
minUsers
, add empty arraybadDays
. - If checking for a day dip of traffic is successful, write in the i-tharray element
badDays
valueexpectedUsers - usersByDay[i]
. Delete current value console log. - If the condition is not fulfilled, write zero in the i-th array element
badDays
. - After the loop, add another
muffin.plot()
command with parametersbadDays
and100
.
Comments