Done with Codecademy Javascript course!

Hooray! I finished up Codecademy’s Javascript course! Here’s the code of the very last lesson, the problems of which I am so proud of having solved. If you plan on taking this course, you miiiiight want to skip this one : )

function StaffMember(name,discountPercent){ = name;
    this.discountPercent = discountPercent;

var sally = new StaffMember("Sally",5);
var bob = new StaffMember("Bob",10);
var me = new StaffMember("Rachel",20);

var cashRegister = {
    lastTransactionAmount: 0,
    add: function(itemCost){ += (itemCost || 0);
        this.lastTransactionAmount = itemCost; // only figured out where to put this stmt w/ help
    scan: function(item,quantity){
        switch (item){
        case "eggs": this.add(0.98 * quantity); break;
        case "milk": this.add(1.23 * quantity); break;
        case "magazine": this.add(4.99 * quantity); break;
        case "chocolate": this.add(0.45 * quantity); break;
        return true;
    voidLastTransaction : function(){ -= this.lastTransactionAmount;
        this.lastTransactionAmount = 0;
    // Create a new method applyStaffDiscount here
    applyStaffDiscount: function(employee) { = - ( * (employee.discountPercent / 100)); // mmm math

// Apply your staff discount by passing the 'me' object 
// to applyStaffDiscount

// Show the total bill
console.log('Your bill is '; // `toFixed(2)` appears to limit the
                                                            // number of decimals of the output to 2.


$ Your bill is 13.744

Finally, an example of a class complex enough for me to see how it’s really used! As my friend Jules said, codecademy is a great way to get a snapshot of a language in action. Being fairly comfortable with Python, Javascript was an awesome class to take. I’ll be wrangling a wrap-up at some point soon, mostly to cover all the ways that an object can be created with/without methods, how they can be edited, and how they can instantiate. STAY TUNED FRIENDS


2 thoughts on “Done with Codecademy Javascript course!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s