0
0
Javascriptprogramming~10 mins

Object use cases in Javascript - Interactive Code Practice

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

Complete the code to create an object with a property 'name' set to 'Alice'.

Javascript
const person = { name: [1] };
Drag options to blanks, or click blank then click option'
A'Alice'
BAlice
C"name"
Dname
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Forgetting quotes around string values.
Using the property name instead of the value.
2fill in blank
medium

Complete the code to access the 'age' property from the object 'user'.

Javascript
const age = user[1]age;
Drag options to blanks, or click blank then click option'
A['']
B::
C->
D.
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using incorrect symbols like '->' or '::'.
Using brackets without quotes.
3fill in blank
hard

Fix the error in the code to add a new property 'city' with value 'Paris' to the object 'location'.

Javascript
location[1]city = 'Paris';
Drag options to blanks, or click blank then click option'
A[]
B->
C.
D::
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using arrow or double colon symbols.
Trying to use brackets without quotes.
4fill in blank
hard

Fill both blanks to create an object 'scores' with keys as player names and values as their points, but only include players with points greater than 10.

Javascript
const scores = {};
for (const player of players) {
  if (player.points > 10) {
    scores[[1]] = [2];
  }
};
Drag options to blanks, or click blank then click option'
Aplayer.name
Bplayer.points
Cplayer.score
Dplayer.value
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using wrong property names like score or value.
Mixing keys and values.
5fill in blank
hard

Fill all three blanks to create a function that returns an object with keys as uppercase names and values as ages, but only for people older than 18.

Javascript
function adultAges(people) {
  return people.reduce((acc, [1]) => {
    if ([2].age > 18) {
      acc[[3]] = [2].age;
    }
    return acc;
  }, {});
}
Drag options to blanks, or click blank then click option'
Aperson
Bp
Cp.name.toUpperCase()
Dperson.name.toUpperCase()
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using different variable names inconsistently.
Not converting names to uppercase.
Mixing parameter names in different places.