freeCodeCamp/curriculum/challenges/arabic/02-javascript-algorithms-an.../es6/use-getters-and-setters-to-...

1.3 KiB

id title challengeType videoUrl localeTitle
587d7b8c367417b2b2512b54 Use getters and setters to Control Access to an Object 1

Description

undefined

Instructions

undefined

Tests

tests:
  - text: ''
    testString: 'assert(typeof Thermostat === "function" && typeof Thermostat.constructor === "function","<code>Thermostat</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 t = new Thermostat(32); return typeof t === "object" && t.temperature === 0;}, "<code>Thermostat</code> can be instantiated.");'

Challenge Seed

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

  /* Alter code above this line */
  return Thermostat;
}
const Thermostat = makeClass();
const thermos = new Thermostat(76); // setting in Fahrenheit scale
let temp = thermos.temperature; // 24.44 in C
thermos.temperature = 26;
temp = thermos.temperature; // 26 in C

Solution

// solution required