From fb85c0c4f56f0a025137a433cde12a37f3d21ef3 Mon Sep 17 00:00:00 2001 From: Samuel Plumppu Date: Sat, 4 Feb 2017 11:50:47 +0100 Subject: [PATCH] fix(challenge): Stricter tests for "OOP: Constructor property" * Also fixed an misleading sentence in the instruction. --- .../object-oriented-programming.json | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/challenges/02-javascript-algorithms-and-data-structures/object-oriented-programming.json b/challenges/02-javascript-algorithms-and-data-structures/object-oriented-programming.json index 1b48605dce..e197702761 100644 --- a/challenges/02-javascript-algorithms-and-data-structures/object-oriented-programming.json +++ b/challenges/02-javascript-algorithms-and-data-structures/object-oriented-programming.json @@ -407,12 +407,12 @@ "description": [ "There is a special constructor property located on the object instances duck and beagle that were created in the previous challenges:", "
let duck = new Bird();
let beagle = new Dog();

console.log(duck.constructor === Bird); //prints true
console.log(beagle.constructor === Dog); //prints true
", - "Note that the constructor property is the name of the constructor function that created the instance.", + "Note that the constructor property is a reference to the constructor function that created the instance.", "The advantage of the constructor 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:", "
function joinBirdFraternity(candidate) {
  if (candidate.constructor === Bird) {
    return true;
  } else {
    return false;
  }
}
", "Note
Since the constructor property can be overwritten (which will be covered in the next two challenges) it’s generally better to use the instanceof method to check the type of an object.", "
", - "Write a joinDogFraternity function that takes a candidate parameter and returns true if the candidate is a Dog and returns false otherwise." + "Write a joinDogFraternity function that takes a candidate parameter and, using the constructor property, return true if the candidate is a Dog, otherwise return false." ], "challengeSeed": [ "function Dog(name) {", @@ -427,7 +427,8 @@ ], "tests": [ "assert(typeof(joinDogFraternity) === 'function', 'message: joinDogFraternity should be defined as a function.');", - "assert(joinDogFraternity(new Dog(\"\")) === true, 'message: joinDogFraternity should return true ifcandidate is an instance of Dog.');" + "assert(joinDogFraternity(new Dog(\"\")) === true, 'message: joinDogFraternity should return true ifcandidate is an instance of Dog.');", + "assert(/\\.constructor/.test(code) && !/instanceof/.test(code), 'message: joinDogFraternity should use the constructor property.');" ], "solutions": [], "hints": [],