JSFiddle - React, Tailwind, and code Playground

by Mohammed Ismail Ansari

HTML

<div id="output-div">
    
</div>

JavaScript

// Everything in JavaScript is an object


// Writes the provided text onto the screen
function writeLine(someText) {
    $("#output-div").append(someText + "<br />");
}

// Works like a class
function person(name, age) {
    self = this;
    
    this.name = name;
    this.age = age;
    
    this.introduce = function() {
        writeLine("I am " + self.name + ", I am " + self.age + " years old.");
    }
}

// Runs at document load
$(document).ready(function(){
    var newPerson = new person("David Anderson", 50);
    newPerson.introduce();
});