- script.js
JavaScript
var expectedUsers = 1000;
var usersByDay = [812, 1360, 657, 1247];
// Drawing the traffic graph
muffin.plot(usersByDay, expectedUsers);
// Summarizing traffic
var totalUsers = 0;
for (var i = 0; i <= usersByDay.length - 1; i++) {
totalUsers += usersByDay[i];
}
console.log(totalUsers);
// Calculating the average traffic value
var averageUsers = 0;
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
Let’s finish program refactoring.
- Remove logging of the
totalUsers
variable in the console. - Set
averageUsers
variable tototalUsers / usersByDay.length
value instead of zero. - Replace the data inside the array
usersByDay
with data received from Muffin. Copy them from theory and insert them between square brackets.
Comments