Giter Club home page Giter Club logo

js-lab2's Introduction

Lab Instructions: Object Oriented Programming

Tips: Before you Begin

To view your code and instructions side-by-side, select the following in your VSCode toolbar:

  • View -> Editor Layout -> Two Columns
  • To view this file in Preview mode, right click on this README.md file and Open Preview
  • Select your code file in the code tree, which will open it up in a new VSCode tab.
  • Drag your assessment code files over to the second column.
  • Great work! You can now see instructions and code at the same time.
  • Questions about using VSCode? Please see our support resources here:
    Visual Studio Code on Coursera

To run your JavaScript code

  • Select your JavaScript file
  • Select the "Run Code" button in the upper right hand toolbar of VSCode.
    Ex: It looks like a triangular "Play" button.

Task 1: Code a Person class

Code a Person class, with three parameters in the constructor: name, age, and energy.

Set the default parameters in the Person class as follows:

name = "Tom"

age = 20

energy = 100

Code two methods in the Person class. Name those methods sleep() and doSomethingFun().

The sleep() method should take the existing energy level and increase it by 10.

The doSomethingFun() method should take the existing energy level and decrease it by 10.

Task 2: Code a Worker class

Code a sub-class, inheriting from the Person class, and name it Worker.

The Worker class has two additional parameters in the constructor:

  • xp (for "experience points")
  • hourlyWage.

These properties are set to the following default values:

xp = 0

hourlyWage = 10

The Worker class has all the paramerters and methods of its super-class.

Additionally, it has the goToWork() method, which, whenever it's run, increases the value of the xp property by 10.

Task 3: Code a intern object

Inside the intern function instantiate the Worker class to code a new intern object.

The intern should have the following characteristics:

name: Bob

age: 21

energy: 110

xp: 0

hourlyWage: 10

Run the goToWork() method on the intern object. Then return the intern object.



Task 4: Code a manager object

Inside the manager function instantiate the Worker class to code a new manager object.

The manager object should have the following characteristics:

name: Alice

age: 30

energy: 120

xp: 100

hourlyWage: 30

Run the doSomethingFun() method on the manager object. Then return the manager object.



Nice work!

js-lab2's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.