Class Practice Challenge

Create a simple JavaScript class that has two different methods. Instantiate the class and call both methods so you can see them run in the console.

Code Runner Challenge

Define a class with at least two methods and use them from an instance.

View IPYNB Source
%%js
// CODE_RUNNER: Homework challenge – create a class and add two methods, then invoke them.

class MyClass {
    constructor(name) {
        this.name = name;
    }

    greet() {
        console.log(`Hello, my name is ${this.name}`);
    }

    farewell() {
        console.log(`Goodbye from ${this.name}`);
    }
}

const obj = new MyClass("Test");
obj.greet();
obj.farewell();
Lines: 1 Characters: 0
Output
Click "Run" in code control panel to see output ...