JSFiddle - React, Tailwind, and code Playground

by imparator

JavaScript

function createCar(price, horsePower, yearMade) {
    return {
        price: price,
        horsePower: horsePower,
        yearMade: yearMade
    }
}

function getHorsePower(car) {
    return car.horsePower;
}

c = createCar('19999.99', '140', '2010');
alert(getHorsePower(c));
// will print 140 on the console

function createAnotherCar(price, horsePower, yearMade) {
    return {
        price: price,
        horsePower: horsePower,
        yearMade: yearMade,
        getHorsePower: function() {
            return this.horsePower;
        }
    }
}
c2 = createAnotherCar('19999.99', '150', '2010');
alert(getHorsePower(c2));
// will alert 150 on the console
    
function Car(price, horsePower, yearMade) {
    this.price = price;
    this.horsePower = horsePower;
    this.yearMade = yearMade;
    this.getHorsePower = function() { return this.horsePower;};            
}
c3 = new Car('19999.99', '160', '2010');
alert(c3.getHorsePower());
// will alert 160 on the console