Skip to content
Foxipa
Code Completion 8 Challenges

Complete the objects and prototypes code

Practice prototype creation, property ownership, lookup, shared methods, and descriptors.

Intermediate ~8 min read

Challenge 1

Create an object that delegates to base.

javascript Your answer
const base = { theme: "dark" };
const settings = ;

Press Ctrl⌘Enter to check your answer

Challenge 2

Check whether title belongs directly to item.

javascript Your answer
const item = Object.create({ title: "inherited" });
item.name = "Guide";
const result = Object.(item, "title");

Press Ctrl⌘Enter to check your answer

Challenge 3

Test for an inherited property too.

javascript Your answer
const base = { role: "admin" };
const user = Object.create(base);
const result = "role"  user;

Press Ctrl⌘Enter to check your answer

Challenge 4

Read an object’s prototype.

javascript Your answer
const base = {};
const child = Object.create(base);
const result = Object.(child);

Press Ctrl⌘Enter to check your answer

Challenge 5

Define the shared method on the prototype.

javascript Your answer
function User(name) { this.name = name; }
User.prototype. = function () { return this.name; };

Press Ctrl⌘Enter to check your answer

Challenge 6

Create an own property through assignment.

javascript Your answer
const proto = { count: 0 };
const object = Object.create(proto);
object. = 3;

Press Ctrl⌘Enter to check your answer

Challenge 7

Make a data property non-writable.

javascript Your answer
const box = {};
Object.defineProperty(box, "value", { value: 1,  });

Press Ctrl⌘Enter to check your answer

Challenge 8

Create a null-prototype dictionary.

javascript Your answer
const dictionary = Object.(null);

Press Ctrl⌘Enter to check your answer