;(function(){
var Mechanic = function(){
};
Mechanic.prototype = {
fix: function(bicycles){
for(var i = 0; i < bicycles.length; ++i){
bicycles[i].fixed = true;
}
},
statistics: function(bicycles){
var red = 0;
var green = 0;
var blue = 0;
var orange = 0;
for(var i = 0; i < bicycles.length; ++i){
switch(bicycles[i].color){
case 'red':
red++;
break;
case 'green':
green++;
break;
case 'blue':
blue++;
break;
case 'orange':
orange++;
break;
}
}
console.log('There are '+red+' red bicycles.');
console.log('There are '+green+' green bicycles.');
console.log('There are '+blue+' blue bicycles.');
console.log('There are '+orange+' orange bicycles.');
}
};
var Bicycle = function(color, size, fixed){
this.color = color;
this.size = size;
this.fixed = fixed;
};
var Trip = function(){
var colors = ['red', 'green', 'blue', 'orange'];
var sizes = ['XS', 'S', 'M', 'L', 'XL'];
this.bicycles = [];
for(var i = 0; i < 200; i++){
this.bicycles.push(new Bicycle(
colors[Math.floor(Math.random()*colors.length)],
sizes[Math.floor(Math.random()*sizes.length)],
false
));
}
};
Trip.prototype = {
prepare: function(){
var mechanic = new Mechanic();
mechanic.fix(this.bicycles);
mechanic.statistics(this.bicycles);
}
};
var trip = new Trip();
...
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.