Quotes help make search much faster. Example: "Practice Makes Perfect"

Thursday, December 6, 2012

Codecademy: Codeyear Let's get paid!


//sample solution


var cashRegisterWithChange = {
    total: 0,
    setTotal: function (amount) {
        this.total = amount;
    },
    getPaid: function (amountPaid) {
        //fill this in
        if(amountPaid<this.total){
console.log("Not enough!");
        } else {
var change = amountPaid - this.total;
console.log(Math.floor(change*100)+" pennies");
        }
}
};

//some tests - you should see the following output:
//  Not enough!
//  45 pennies
cashRegisterWithChange.setTotal(2.55);
cashRegisterWithChange.getPaid(2);
cashRegisterWithChange.getPaid(3);

No comments:

Post a Comment


This is an example of scrolling text using Javascript.

Popular Posts