Your first class
JavaScript · Unit 12: Classes and objects
- Full plan
- JavaScript
- 9 exercises
A class is a mold for making objects of the same kind. class Pet {} creates the mold, and new Pet() creates a new object from that mold.
That object is like the ones you already know: you give it properties with a dot.
class Pet {}
const luna = new Pet();
luna.name = "Luna";
console.log(luna.name);Prints
Luna
The rest of the explanation is in the lesson, which is part of the full plan.
Exercises in this lesson
You do them in the app, which checks them on the spot and explains why.
1. Multiple choice
class Pet {}already exists. Which line creates an object from that mold?2. Complete the code
Fill in the blank to create a book with the
Bookclass.3. Predict the output
What does this code print?
4. Predict the output
What does this code print?
5. Predict the output
There's only one
newhere. What does it print?6. Multiple choice
A school program has a
Studentclass and two objects,miaandleo. Which sentence is right?7. Find the bug
This program should print "Coco". Which line has the bug?
8. Put the lines in order
Put the lines in order to create a ticket to Boston and print its city.
9. Predict the output
One ticket is made per city. What does it print?
It opens in your browser. This lesson is part of the full plan; the first unit of each course is free.