JS
…

Module 1 of 1

classes

Constructors, methods, inheritance, and this — the javascript.info OOP core.

Classes & OOP · 0/6 completed · scroll down for every challenge

Challenge 1 of 6

Class field

Instructions

Create class `User` with constructor `(name)` storing `this.name`.

Editor

IntelliSense on

// Write your code below

Challenge 2 of 6 · Instance method

Challenge 2 of 6

Instance method

Instructions

Add `hello()` on `User` that returns `"Hi, ${this.name}"`.

Editor

IntelliSense on

// Write your code below

Challenge 3 of 6 · Extends

Challenge 3 of 6

Extends

Instructions

Create `Admin` extending `User` with extra `role` set to `"admin"`. Keep the User constructor.

Editor

IntelliSense on

// Write your code below

Challenge 4 of 6 · Static method

Challenge 4 of 6

Static method

Instructions

Create class `Mathy` with static `double(n)` returning n * 2.

Editor

IntelliSense on

// Write your code below

Challenge 5 of 6 · Getter

Challenge 5 of 6

Getter

Instructions

Create class `Box` with constructor `(w, h)` and getter `area` returning w * h.

Editor

IntelliSense on

// Write your code below

Challenge 6 of 6 · This in method

Challenge 6 of 6

This in method

Instructions

Create `Counter` with `n = 0` and `inc()` that adds 1 to `this.n` and returns it.

Editor

IntelliSense on

// Write your code below

Next module