Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
π‘ Hint
Common Mistakes
Forgetting to put quotes around the string value.
Using a variable name instead of a string.
β Incorrect
The name value must be a string, so it needs quotes around it.
2fill in blank
mediumComplete 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'
Attempts:
3 left
π‘ Hint
Common Mistakes
Using the value instead of the property name.
Using a wrong property name.
β Incorrect
To get the age, use the property name 'age' after the dot.
3fill in blank
hardFix 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'
Attempts:
3 left
π‘ Hint
Common Mistakes
Using '=' instead of '.' before the property name.
Using brackets without quotes.
β Incorrect
Use dot notation to add a new property to an object.
4fill in blank
hardFill 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'
Attempts:
3 left
π‘ Hint
Common Mistakes
Forgetting quotes around the greeting string.
Using the wrong property name after 'this'.
β Incorrect
The method returns a greeting string plus the object's name property.
5fill in blank
hardFill 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'
Attempts:
3 left
π‘ Hint
Common Mistakes
Mixing up property names inside the method.
Not using 'this' to access object properties.
β Incorrect
The method uses the title and author properties to create a summary string.