Console Cash Register

Cash Register to replace the "Building a Cash Register" section on Codecademy

by Taylor Lopez

HTML

<div id="content"></div>

CSS

html, body 
{
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
    /* Background Color */
    background-color: black;
}

#content
{
    padding: 10px;
    font-family:"Lucida Console", "Courier New", "Courier";
    /* Console Text Color */
    color: #0F0;    /* Lime Green */
}

/* console span properties */
.consoleLine
{
}

JavaScript

/* START CONSOLE FUNCTIONALITY -- DON'T TOUCH */
// This function intercepts the console.log() calls and prints the output to the result pane to the right like a standard console instead of the hidden console. Just pretend like this isn't heeeereee. ooooooooooohhh. *spooky*
var _console = document.getElementById("content"); var _body = document.getElementsByTagName("body")[0]; console.log = function (object) { var output = object === undefined ? "" : object.toString(); output = output.replace(/ /g, "&nbsp;"); while (output.search('\n') !== -1) output = output.replace('\n', "<br />"); _console.innerHTML += ("<span class='consoleLine'>" + output + "</span><br />"); window.scrollTo(0, _body.scrollHeight); };
/* END OF CONSOLE FUNCTIONALITY */

/****************************** YOUR CODE START ******************************/

/* CLASSES */
function CashRegister()
{
    this.total = 0;
    var lastTransactionAmount = 0;
}
CashRegister.prototype.add = function(itemCost)
{
    this.total += itemCost;
    lastTransactionAmount = itemCost;
};
CashRegister.prototype.scan = function(item, qty)
{
    switch(item)
    {
        case "eggs": this.add(0.98 * qty); break;
        case "milk": this.add(1.23 * qty); break;
        case "magazine": this.add(4.99 * qty); break;
        case "chocolate": this.add(0.45 * qty); break;
    }
    return true;
};
CashRegister.prototype.voidLastTransaction = function()
{
    this.total -= lastTransactionAmount;
};
CashRegister.prototype.applyStaffDiscount = function(employee)
{
    console.log("Welcome, " + employee.name);
    var first = this.total;
    this.total *= ((100 - employee.discountPercent) / 100);
    var second = this.total;
    console.log("Your total was " + this.moneyFormat(first) + ".");
    console.log("With your " + employee.discountPercent + "% discount, it's " + this.moneyFormat(second) + ".");
    console.log("You saved " + this.moneyFormat(first - second) + "!");
};
CashRegister.moneyFormat = function(number)
{
   ...