|
407 | 407 | "description": [
|
408 | 408 | "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:",
|
409 | 409 | "<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.", |
411 | 411 | "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:",
|
412 | 412 | "<blockquote>function joinBirdFraternity(candidate) {<br> if (candidate.constructor === Bird) {<br> return true;<br> } else {<br> return false;<br> }<br>}</blockquote>",
|
413 | 413 | "<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.",
|
414 | 414 | "<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>." |
416 | 416 | ],
|
417 | 417 | "challengeSeed": [
|
418 | 418 | "function Dog(name) {",
|
|
427 | 427 | ],
|
428 | 428 | "tests": [
|
429 | 429 | "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.');" |
431 | 432 | ],
|
432 | 433 | "solutions": [],
|
433 | 434 | "hints": [],
|
|
0 commit comments