A. person.age() is incorrect because age is not a function
B. person['age'] should be person.age()
C. Missing semicolon after object declaration
D. person.name is undefined
Solution
Step 1: Identify property types in the object
person has keys 'name' and 'age' with values 'Bob' and 25 (a number), not functions.
Step 2: Check method call usage
person.age() tries to call age as a function, but age is a number, causing an error.
Final Answer:
person.age() is incorrect because age is not a function -> Option A
Quick Check:
Only functions can be called with () [OK]
Hint: Only call functions with () not plain values [OK]
Common Mistakes:
Calling a number or string as a function
Confusing bracket and dot notation usage
Assuming missing semicolons cause runtime errors
5. You want to store a list of students with their scores and add a method to calculate the average score. Which object structure is best?
hard
A. const students = { 'Anna': 90, 'Ben': 80 };
B. const students = ['Anna', 90, 'Ben', 80];
C. const students = { list: [{name: 'Anna', score: 90}, {name: 'Ben', score: 80}], average: function() { /* calculate average */ } };
D. const students = function() { return ['Anna', 90, 'Ben', 80]; };
Solution
Step 1: Identify need for data and method together
We want to store multiple students with scores and a method to calculate average, so an object with a list and a function is suitable.
Step 2: Evaluate each option
const students = { list: [{name: 'Anna', score: 90}, {name: 'Ben', score: 80}], average: function() { /* calculate average */ } }; uses an object with a list of student objects and a method for average calculation. const students = ['Anna', 90, 'Ben', 80]; is a flat array without structure. const students = { 'Anna': 90, 'Ben': 80 }; lacks a method. const students = function() { return ['Anna', 90, 'Ben', 80]; }; is a function, not an object with data and method.
Final Answer:
const students = { list: [{name: 'Anna', score: 90}, {name: 'Ben', score: 80}], average: function() { /* calculate average */ } }; -> Option C
Quick Check:
Object with data + method = const students = { list: [{name: 'Anna', score: 90}, {name: 'Ben', score: 80}], average: function() { /* calculate average */ } }; [OK]
Hint: Use objects with arrays and methods for grouped data and actions [OK]
Common Mistakes:
Using arrays without methods for complex data
Not grouping related data in objects
Confusing functions with data containers
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.