Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation


Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

              ///////////////////////////////// Writing Methods ////////////////////////////////

// As mentioned earlier, objects can have methods that we can invoke to perform some kind of function or action on the object

// Methods are stored as an object property, but are programmed by defining a new function to assign the property to

// To look at a few examples, we will use the employee object below:

// The employee object will represent an employee of our imaginary company, Katie Johnson.

// This object stores the information for employee Katie Johnson, with properties for her name, ID, phone number, address, hourly wage, and number of hours worked this week.

// The last property of the employee object will be the method called "printEmployeeInfo"

// The printEmployeeInfo method declares a new function that returns the employee ID and full name in a formatted order

// You'll notice that the method uses a new keyword we haven't worked with yet, "this"

// When used in an object method, the 'this' keyword refers to the object in context.

// On line 30, this.firstName is equivalent to saying employee.firstName:
let employee = {
  firstName: "Katie",
  lastName: "Johnson",
  employeeID: 295025,
  phone: 4560001234,
  address: "42 Wallaby Way",
  wage: 13.5,
  hoursWorked: 25,
  printEmployeeInfo: function() {
    return (
      "Employee #" +
      this.employeeID +
      " : " +
      this.firstName +
      " " +


// Next, lets add a method to the employee object that calculates their weekly pay
// This method will be called "paycheck" and will return the product of the employee object's wage property and the employee object's hoursWorked property:

employee.paycheck = function() {
  return "$" + this.wage * this.hoursWorked;

// Now, we can invoke the paycheck method like so:

let income = employee.paycheck();

// or:

  "Employee #" +
    employee.employeeID +
    " worked " +
    employee.hoursWorked +
    " hours this week and earned " +

// Try updating the hoursWorked property to a number greater than 25, and invoking the paycheck method again:

employee.hoursWorked = 40;
  "Employee #" +
    employee.employeeID +
    " worked " +
    employee.hoursWorked +
    " hours this week and earned " +

// Finally, lets write an employee contacy information method.

// The method will be named "contact" and will print the information to the console in this order:

// Employee #ID - Last Name, First Name , Phone: (###)-###-#### , Address: __________ = function() {
  return (
    "Employee #" +
    this.employeeID +
    " - " +
    this.lastName +
    ", " +
    this.firstName +
    " , Phone: (" +, 3) +
    ")-" +, 6) +
    "-" +, 10) +
    " , Address: " +

// Now we can invoke this method and print its return statement to the console:

///////////////////////// Exercises /////////////////////////
//1. Create a new object representing a pizza place's customer with the following properties: customerName(string), orderID(number), order(string), orderTotal(number), payed(boolean)
// assign appropriate values to each of the object's properties
//2. Declare a new method named printOrder that returns the object's properties in this format: "Order #(Customer ID goes here): (order goes here) = (order total goes here)"
//3. Invoke the method and print it to the console
//4. Declare a new method called "pay" that changes the value of the payed boolean property to True
//5. Declare a new method called "receipt" that uses a conditional to check if the customer has payed, and if so, and returns "(Customer Name) payed (order total) for order #(orderID)"
// If the customer has not payed, the method should return "Awaiting customer payment for order #(order ID)"
//6. Call the receipt method before calling the pay method to ensure the else statement is executed when necessary.

🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.