function RgbColor(r, g, b) {
    'use strict';

    //The three main properties of the object
    this.r = (0 <= r && r <= 255) ? r : 255;
    this.g = (0 <= g && g <= 255) ? g : 255;
    this.b = (0 <= b && b <= 255) ? b : 255;

    //Picks the next random color
    this.randomize = function () {
        this.r = this.rn();
        this.g = this.rn();
        this.b = this.rn();
    };

    //Provides an array representation of the object
    this.toArray = function () {
        var a = [];
        a.push(this.r);
        a.push(this.g);
        a.push(this.b);
        return a;
    };

    //Provides a CSS-formatted string representing the color
    this.toString = function () {
        return 'rgb(' + this.toArray() + ')';
    };

    //Random number generator from 0 to 255
    this.rn = function () {
        return Math.round(Math.random() * 255);
    };

    //Compares RgbColor object properties, returns true if same
    this.isSame = function (rgb) {
        if (rgb instanceof RgbColor) {
            var i, thisArray = this.toArray(),
                thatArray = rgb.toArray();
            for (i = 0; i < thatArray.length; i += 1) {
                if (thisArray[i] !== thatArray[i]) {
                    return false;
                }
            }
            return true;
        }
    };

    //Returns a CSS-formatted string representing the inverse color
    this.inverseToString = function () {
        var inverseArray = [],
            a = this.toArray();
        a.forEach(function (item) {
            inverseArray.push(255 - item);
        });
        return 'rgb(' + inverseArray + ')';
    };
}
// Object Constructor - Used to randomly create colors in RGB format
Object Constructor - Used to randomly create colors in RGB format
Object Constructor - Used to randomly create colors in RGB format
function RgbColor(r, g, b) {
    'use strict';
    this.r = (0 <= r && r <= 255) ? r : 255;
    this.g = (0 <= g && g <= 255) ? g : 255;
    this.b = (0 <= b && b <= 255) ? b : 255;
    this.randomize = function () {
        this.r = this.rn();
        this.g = this.rn();
        this.b = this.rn();
    };
    this.toArray = function () {
        var a = [];
        a.push(this.r);
        a.push(this.g);
        a.push(this.b);
        return a;
    };
    this.toString = function () {
        return 'rgb(' + this.toArray() + ')';
    };
    this.rn = function () {
        return Math.round(Math.random() * 255);
    };
    this.isSame = function (rgb) {
        if (rgb instanceof RgbColor) {
            var i, thisArray = this.toArray(),
                thatArray = rgb.toArray();
            for (i = 0; i < thatArray.length; i += 1) {
                if (thisArray[i] !== thatArray[i]) {
                    return false;
                }
            }
            return true;
        }
    };
    this.inverseToString = function () {
        var inverseArray = [],
            a = this.toArray();
        a.forEach(function (item) {
            inverseArray.push(255 - item);
        });
        return 'rgb(' + inverseArray + ')';
    };
}
function RgbColor ( r , g , b ) { 'use strict' ; this . r = ( 0 <= r && r <= 255 ) ? r : 255 ; this . g = ( 0 <= g && g <= 255 ) ? g : 255 ; this . b = ( 0 <= b && b <= 255 ) ? b : 255 ; this . randomize = function ( ) { this . r = this . rn ( ) ; this . g = this . rn ( ) ; this . b = this . rn ( ) ; } ; this . toArray = function ( ) { var a = [ ] ; a . push ( this . r ) ; a . push ( this . g ) ; a . push ( this . b ) ; return a ; } ; this . toString = function ( ) { return 'rgb(' + this . toArray ( ) + ')' ; } ; this . rn = function ( ) { return Math . round ( Math . random ( ) * 255 ) ; } ; this . isSame = function ( rgb ) { if ( rgb instanceof RgbColor ) { var i , thisArray = this . toArray ( ) , thatArray = rgb . toArray ( ) ; for ( i = 0 ; i < thatArray . length ; i += 1 ) { if ( thisArray [ i ] !== thatArray [ i ] ) { return false ; } } return true ; } } ; this . inverseToString = function ( ) { var inverseArray = [ ] , a = this . toArray ( ) ; a . forEach ( function ( item ) { inverseArray . push ( 255 - item ) ; } ) ; return 'rgb(' + inverseArray + ')' ; } ; }
Object Constructor - Used to randomly create colors in RGB format
Object Constructor - Used to randomly create colors in RGB format
//The three main properties of the object //Picks the next random color //Provides an array representation of the object //Provides a CSS-formatted string representing the color //Random number generator from 0 to 255 //Compares RgbColor object properties, returns true if same //Returns a CSS-formatted string representing the inverse color