JSFiddle - React, Tailwind, and code Playground

by Amando Filipe

JavaScript

;(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();
   ...