SomeDer bfa5c26288 fix: use dfn instead of code tag (#36640)
* Use dfn tags

* remove misused <dfn> tags

* Revert "remove misused <dfn> tags"

This reverts commit b24968a96810f618d831410ac90a0bc452ebde50.

* Update curriculum/challenges/english/01-responsive-web-design/basic-html-and-html5/fill-in-the-blank-with-placeholder-text.english.md

Co-Authored-By: Randell Dawson <5313213+RandellDawson@users.noreply.github.com>

* Make "array" lowercase

Co-Authored-By: Randell Dawson <5313213+RandellDawson@users.noreply.github.com>

* Fix dfn usage

* Address last dfn tags
2019-10-27 12:45:37 -04:00

2.1 KiB

id, title, challengeType, forumTopicId
id title challengeType forumTopicId
587d7dad367417b2b2512b77 Define a Constructor Function 1 16804

Description

Constructors are functions that create new objects. They define properties and behaviors that will belong to the new object. Think of them as a blueprint for the creation of new objects. Here is an example of a constructor:
function Bird() {
  this.name = "Albert";
  this.color = "blue";
  this.numLegs = 2;
}

This constructor defines a Bird object with properties name, color, and numLegs set to Albert, blue, and 2, respectively. Constructors follow a few conventions:

  • Constructors are defined with a capitalized name to distinguish them from other functions that are not constructors.
  • Constructors use the keyword this to set properties of the object they will create. Inside the constructor, this refers to the new object it will create.
  • Constructors define properties and behaviors instead of returning a value as other functions might.

Instructions

Create a constructor, Dog, with properties name, color, and numLegs that are set to a string, a string, and a number, respectively.

Tests

tests:
  - text: <code>Dog</code> should have a <code>name</code> property set to a string.
    testString: assert(typeof (new Dog()).name === 'string');
  - text: <code>Dog</code> should have a <code>color</code> property set to a string.
    testString: assert(typeof (new Dog()).color === 'string');
  - text: <code>Dog</code> should have a <code>numLegs</code> property set to a number.
    testString: assert(typeof (new Dog()).numLegs === 'number');

Challenge Seed


Solution

function Dog (name, color, numLegs) {
  this.name = 'name';
  this.color = 'color';
  this.numLegs = 4;
}