// 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
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.