mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-10-24 23:49:06 +08:00
fix(curriculum): rounding issue in getter/setter challenge (#50560)
This commit is contained in:
+18
-45
@@ -61,80 +61,53 @@ In other words, you are abstracting implementation details from the user.
|
||||
`Thermostat` should be a `class` with a defined `constructor` method.
|
||||
|
||||
```js
|
||||
assert(
|
||||
typeof Thermostat === 'function' &&
|
||||
typeof Thermostat.constructor === 'function'
|
||||
);
|
||||
assert.isFunction(Thermostat);
|
||||
assert.isFunction(Thermostat?.constructor);
|
||||
```
|
||||
|
||||
`class` keyword should be used.
|
||||
The `class` keyword should be used.
|
||||
|
||||
```js
|
||||
assert(code.match(/class/g));
|
||||
assert.match(code, /class/);
|
||||
```
|
||||
|
||||
`Thermostat` should be able to be instantiated.
|
||||
|
||||
```js
|
||||
assert(
|
||||
(() => {
|
||||
const t = new Thermostat(122);
|
||||
return typeof t === 'object';
|
||||
})()
|
||||
);
|
||||
const _t = new Thermostat(122);
|
||||
assert.isObject(_t);
|
||||
```
|
||||
|
||||
When instantiated with a Fahrenheit value, `Thermostat` should set the correct `temperature`.
|
||||
|
||||
```js
|
||||
assert(
|
||||
(() => {
|
||||
const t = new Thermostat(122);
|
||||
return t.temperature === 50;
|
||||
})()
|
||||
);
|
||||
const _t = new Thermostat(122);
|
||||
assert.strictEqual(_t?.temperature, 50);
|
||||
```
|
||||
|
||||
A `getter` should be defined.
|
||||
|
||||
```js
|
||||
assert(
|
||||
(() => {
|
||||
const desc = Object.getOwnPropertyDescriptor(
|
||||
Thermostat.prototype,
|
||||
'temperature'
|
||||
);
|
||||
return !!desc && typeof desc.get === 'function';
|
||||
})()
|
||||
);
|
||||
const _desc = Object.getOwnPropertyDescriptor(Thermostat.prototype, 'temperature');
|
||||
assert.isFunction(_desc?.get);
|
||||
```
|
||||
|
||||
A `setter` should be defined.
|
||||
|
||||
```js
|
||||
assert(
|
||||
(() => {
|
||||
const desc = Object.getOwnPropertyDescriptor(
|
||||
Thermostat.prototype,
|
||||
'temperature'
|
||||
);
|
||||
return !!desc && typeof desc.set === 'function';
|
||||
})()
|
||||
);
|
||||
const _desc = Object.getOwnPropertyDescriptor(Thermostat.prototype, 'temperature');
|
||||
assert.isFunction(_desc?.set);
|
||||
```
|
||||
|
||||
Calling the `setter` with a Celsius value should set the `temperature`.
|
||||
|
||||
```js
|
||||
assert(
|
||||
(() => {
|
||||
const t = new Thermostat(32);
|
||||
t.temperature = 26;
|
||||
const u = new Thermostat(32);
|
||||
u.temperature = 50;
|
||||
return t.temperature === 26 && u.temperature === 50;
|
||||
})()
|
||||
);
|
||||
const _t = new Thermostat(32);
|
||||
_t.temperature = 26;
|
||||
const _u = new Thermostat(32);
|
||||
_u.temperature = 50;
|
||||
assert.approximately(_t.temperature, 26, 0.1);
|
||||
assert.approximately(_u.temperature, 50, 0.1);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
Reference in New Issue
Block a user