3.7 KiB
3.7 KiB
id, title, challengeType, forumTopicId, localeTitle
id | title | challengeType | forumTopicId | localeTitle |
---|---|---|---|---|
587d7b89367417b2b2512b49 | Use Destructuring Assignment to Assign Variables from Objects | 1 | 301215 | Использование назначения назначения для назначения переменных из объектов |
Description
var voxel = {x: 3.6, y: 7.4, z: 6.54};Вот тот же оператор присваивания с синтаксисом деструктуризации ES6:
var x = voxel.x; // x = 3.6
var y = voxel.y; // y = 7.4
var z = voxel.z; // z = 6,54
const {x, y, z} = воксел; // x = 3,6, y = 7,4, z = 6,54Если вместо этого вы хотите сохранить значения
voxel.x
в a
, voxel.y
в b
и voxel.z
в c
, у вас тоже есть эта свобода. const {x: a, y: b, z: c} = voxel // a = 3.6, b = 7.4, c = 6.54Вы можете прочитать это как «получить поле
x
и скопировать значение в a
» и так далее.
Instructions
highToday
and highTomorrow
the values of today
and tomorrow
from the HIGH_TEMPERATURES
object.
Tests
tests:
- text: You should remove the ES5 assignment syntax.
testString: assert(!code.match(/highToday = HIGH_TEMPERATURES\.today/g) && !code.match(/highTomorrow = HIGH_TEMPERATURES\.tomorrow/g))
- text: You should use destructuring to create the <code>highToday</code> variable.
testString: assert(code.match(/(var|const|let)\s*{\s*(today:\s*highToday[^}]*|[^,]*,\s*today\s*:\s*highToday\s*)}\s*=\s*HIGH_TEMPERATURES(;|\s+|\/\/)/g));
- text: You should use destructuring to create the <code>highTomorrow</code> variable.
testString: assert(code.match(/(var|const|let)\s*{\s*(tomorrow:\s*highTomorrow[^}]*|[^,]*,\s*tomorrow\s*:\s*highTomorrow\s*)}\s*=\s*HIGH_TEMPERATURES(;|\s+|\/\/)/g));
Challenge Seed
const HIGH_TEMPERATURES = {
yesterday: 75,
today: 77,
tomorrow: 80
};
// change code below this line
const highToday = HIGH_TEMPERATURES.today;
const highTomorrow = HIGH_TEMPERATURES.tomorrow;
// change code above this line
console.log(yesterday) // should be not defined
console.log(highToday); // should be 77
console.log(highTomorrow); // should be 80
Solution
const HIGH_TEMPERATURES = {
yesterday: 75,
today: 77,
tomorrow: 80
};
// change code below this line
const { today: highToday, tomorrow: highTomorrow } = HIGH_TEMPERATURES;
// change code above this line
console.log(highToday); // should be 77
console.log(highTomorrow); // should be 80