Skip to content
This repository was archived by the owner on Sep 25, 2019. It is now read-only.

Commit fb85c0c

Browse files
committed
fix(challenge): Stricter tests for "OOP: Constructor property"
* Also fixed an misleading sentence in the instruction.
1 parent 682cef1 commit fb85c0c

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

challenges/02-javascript-algorithms-and-data-structures/object-oriented-programming.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -407,12 +407,12 @@
407407
"description": [
408408
"There is a special <code>constructor</code> property located on the object instances <code>duck</code> and <code>beagle</code> that were created in the previous challenges:",
409409
"<blockquote>let duck = new Bird();<br>let beagle = new Dog();<br><br>console.log(duck.constructor === Bird); //prints true<br>console.log(beagle.constructor === Dog); //prints true</blockquote>",
410-
"Note that the <code>constructor</code> property is the name of the constructor function that created the instance.",
410+
"Note that the <code>constructor</code> property is a reference to the constructor function that created the instance.",
411411
"The advantage of the <code>constructor</code> property is that it's possible to check for this property to find out what kind of object it is. Here's an example of how this could be used:",
412412
"<blockquote>function joinBirdFraternity(candidate) {<br>&nbsp;&nbsp;if (candidate.constructor === Bird) {<br>&nbsp;&nbsp;&nbsp;&nbsp;return true;<br>&nbsp;&nbsp;} else {<br>&nbsp;&nbsp;&nbsp;&nbsp;return false;<br>&nbsp;&nbsp;}<br>}</blockquote>",
413413
"<strong>Note</strong><br>Since the <code>constructor</code> property can be overwritten (which will be covered in the next two challenges) it’s generally better to use the <code>instanceof</code> method to check the type of an object.",
414414
"<hr>",
415-
"Write a <code>joinDogFraternity</code> function that takes a <code>candidate</code> parameter and returns <code>true</code> if the candidate is a <code>Dog</code> and returns <code>false</code> otherwise."
415+
"Write a <code>joinDogFraternity</code> function that takes a <code>candidate</code> parameter and, using the <code>constructor</code> property, return <code>true</code> if the candidate is a <code>Dog</code>, otherwise return <code>false</code>."
416416
],
417417
"challengeSeed": [
418418
"function Dog(name) {",
@@ -427,7 +427,8 @@
427427
],
428428
"tests": [
429429
"assert(typeof(joinDogFraternity) === 'function', 'message: <code>joinDogFraternity</code> should be defined as a function.');",
430-
"assert(joinDogFraternity(new Dog(\"\")) === true, 'message: <code>joinDogFraternity</code> should return true if<code>candidate</code> is an instance of <code>Dog</code>.');"
430+
"assert(joinDogFraternity(new Dog(\"\")) === true, 'message: <code>joinDogFraternity</code> should return true if<code>candidate</code> is an instance of <code>Dog</code>.');",
431+
"assert(/\\.constructor/.test(code) && !/instanceof/.test(code), 'message: <code>joinDogFraternity</code> should use the <code>constructor</code> property.');"
431432
],
432433
"solutions": [],
433434
"hints": [],

0 commit comments

Comments
 (0)