JSFiddle - React, Tailwind, and code Playground

by puuga

HTML

<body>
    <h1>Object in JavaScript</h1>
    <div>
        <button onclick="goPressed()">Go</button>
    </div>
    <div id="result">
    </div>
</body>

CSS

body {
    margin: 10px;
    font-family: Helvetica;
}
h1 {
    font-size: 140%;
    margin-bottom: 20px;
}
h2 {
    font-size: 110%;
    margin: 10px 0;
}
button, hr {
    margin: 10px 0;
}

JavaScript

// javascript obfect

function goPressed() {
    function person(firstname, lastname, age, favFood) {
        this.firstname = firstname;
        this.lastname = lastname;
        this.age = age;
        this.favFood = favFood;
        this.alertFavFood = function(num) {
            alert(this.age + num);
        }
    }

    var p1 = new person("f", "l", 12, ["salad", "padthai"]);
    p1.alertFavFood(2);
        
    //output
    $("#result").html("1");
}