JSFiddle - React, Tailwind, and code Playground

by Chad Drummond

JavaScript

// Generate a forcast for the next week
// Starting: Monday
// Ending: Sunday

var ForcastList = [];

function addDayToForcast(name, forcast, temperature) {
  ForcastList.push({
    name: name,
    forcast: forcast,
    temperature: temperature
  });
}

addDayToForcast('Sunday', 'Sunny', 74);
addDayToForcast('Monday', 'Sunny', 76);
addDayToForcast('Tuesday', 'Rainy', 64);
addDayToForcast('Wednesday', 'Cloudy', 68);
addDayToForcast('Thursday', 'Cloudy', 64);
addDayToForcast('Friday', 'Sunny', 75);
addDayToForcast('Saturday', 'Partial Clouds', 65);

console.log('ForcastList', ForcastList);

function countSweaterDays() {
  // loop through all of the days
  var sweaterDays = ForcastList.filter(function (day) {
    // check if temperature is lower than 70 degrees
    if (day.temperature < 70) {
      return true;
    }
  });
  
  // return the number of sweater days
  return sweaterDays.length;
}

console.log('Sweater days', countSweaterDays());

// Should I bring my sweater next week?
// - if more than 50% of the days are "sweater days", then I will bring my sweater