freeCodeCamp/curriculum/challenges/arabic/02-javascript-algorithms-an.../es6/use-class-syntax-to-define-...

1.3 KiB

id title challengeType videoUrl localeTitle
587d7b8b367417b2b2512b53 Use class Syntax to Define a Constructor Function 1

Description

undefined

Instructions

undefined

Tests

tests:
  - text: ''
    testString: 'assert(typeof Vegetable === "function" && typeof Vegetable.constructor === "function", "<code>Vegetable</code> should be a <code>class</code> with a defined <code>constructor</code> method.");'
  - text: ''
    testString: 'getUserInput => assert(getUserInput("index").match(/class/g),"<code>class</code> keyword was used.");'
  - text: ''
    testString: 'assert(() => {const a = new Vegetable("apple"); return typeof a === "object";},"<code>Vegetable</code> can be instantiated.");'
  - text: ''
    testString: 'assert(carrot.name=="carrot","<code>carrot.name</code> should return <code>carrot</code>.");'

Challenge Seed

function makeClass() {
  "use strict";
  /* Alter code below this line */

  /* Alter code above this line */
  return Vegetable;
}
const Vegetable = makeClass();
const carrot = new Vegetable('carrot');
console.log(carrot.name); // => should be 'carrot'

Solution

// solution required