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 Bulding(buildingType) {
    console.log("In main function");
    // Changed to function expression and removed name from function
    var 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(buildingType);
        valueGetter(this);
    }).bind(this); // added the bind
    
    this.room = 2;
    this.clr = "green";
    this.scrn = null;
    getType();

    function getType() {
        console.log("In control function");
        switch (buildingType) {
            case "home":
                setBuildingas(2, "green", null);
                break;
            case "office":
                setBuildingas(20, "white", null);
                break;
            case "mall":
                setBuildingas(200, "asorted", null);
                break;
            case "theater":
                setBuildingas(20, "white", "78cm");
                break;
            default:
                console.log("Please Enter Valid Type");
                break;
        }
    }
}

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