0
0
Javascriptprogramming~10 mins

Why objects are needed in Javascript - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create an object representing a person with a name.

Javascript
const person = { name: [1] }; console.log(person.name);
Drag options to blanks, or click blank then click option'
AAlice
B'Alice'
Cname
Dperson
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Forgetting to put quotes around the string value.
Using a variable name instead of a string.
2fill in blank
medium

Complete the code to access the age property of the object.

Javascript
const user = { age: 30 }; console.log(user.[1]);
Drag options to blanks, or click blank then click option'
Aname
Buser
C30
Dage
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using the value instead of the property name.
Using a wrong property name.
3fill in blank
hard

Fix the error in the code to correctly add a new property to the object.

Javascript
const car = {}; car[1]color = 'red'; console.log(car.color);
Drag options to blanks, or click blank then click option'
A.
B[
C=
D:
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using '=' instead of '.' before the property name.
Using brackets without quotes.
4fill in blank
hard

Fill both blanks to create an object with a method that returns a greeting.

Javascript
const greeter = { greet() { return [1] + this.[2]; } , name: 'Bob' }; console.log(greeter.greet());
Drag options to blanks, or click blank then click option'
A'Hello, '
Bname
Cgreet
D'Hi, '
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Forgetting quotes around the greeting string.
Using the wrong property name after 'this'.
5fill in blank
hard

Fill all three blanks to create an object with properties and a method that uses them.

Javascript
const book = { title: [1], author: [2], getSummary() { return `${this.[3] by ${this.author}`; } }; console.log(book.getSummary());
Drag options to blanks, or click blank then click option'
A'1984'
B'George Orwell'
Ctitle
Dauthor
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Mixing up property names inside the method.
Not using 'this' to access object properties.