JSFiddle - React, Tailwind, and code Playground

by akang2

HTML

<html>
    <body>
    </body>
</html>

JavaScript

//new object
function computer(speed,hdspace,ram){
    this.speed=speed;
    this.hdspace=hdspace;
    this.ram=ram;
    this.price=get_price;
}

//method
function get_price(){
    var thePrice=500;
    thePrice+=(this.speed=='2ghz')?200:100;
    thePrice+=(this.hdspace=='80gb')?50:25;
    thePrice+=(this.ram=='1gb')?150:75;
    return thePrice;
}

//creating the instance
var work_comp=new computer("2ghz","80gb","1gb");
var home_comp=new computer('1.5ghz','40gb','512mb');
var laptop=new computer('1ghz','20gb','256mb');

//assign var's to the method results
var workComputerPrice=work_comp.price();
var homeComputerPrice=home_comp.price();
var laptopComputerPrice=laptop.price();

document.write(workComputerPrice);
document.write("<br />");
document.write("<br />");
document.write(homeComputerPrice);
document.write("<br />");
document.write("<br />");
document.write(laptopComputerPrice);
document.write("<br />");
document.write('<br />');
document.write(navigator.cookieEnabled);
document.write("<br />");
document.write('<br />');
document.write(home_comp.hdspace + " " + laptop.speed);