JSFiddle - React, Tailwind, and code Playground

by Graham Fairweather

JavaScript

// Moved here because I like defining things before they are used.
function valueGetter(obj) {
    // Using ECMA5 methods instead, just example
    Object.keys(obj).forEach(function (key) {
        console.log(key + " has value of " + this[key]);
    }, obj);
}

// I like constructors to begin with a capital letter
function Building(buildingType) {
    console.log("In main function");    
    this.room = 2;
    this.clr = "green";
    this.scrn = null;
    this.buildingType = buildingType;
    this.getType();
}

Building.prototype = {
    setBuildingas: function (noOfRooms, buldingColor, theaterScreen) {
        this.room = noOfRooms;
        this.clr = buldingColor;
        this.scrn = theaterScreen;
        // I guess you want to see the contents of 'this' rather than 'buildingType'
        console.log(this.buildingType);
        valueGetter(this);
        
        return this;
    },
    
    getType: function () {
        console.log("In control function");
        switch (this.buildingType) {
            case "home":
                this.setBuildingas(2, "green", null);
                break;
            case "office":
                this.setBuildingas(20, "white", null);
                break;
            case "mall":
                this.setBuildingas(200, "asorted", null);
                break;
            case "theater":
                this.setBuildingas(20, "white", "78cm");
                break;
            default:
                console.log("Please Enter Valid Type");
        }
        
        return this;
    }
};

console.log("In Script");
// I like one 'var'
var house = new Building("home"),
    house2 = new Building("mall"),
    house3 = new Building("theater");