Challenge use-destructuring-assignment-to-assign-variables-from-objects & Challenge use-destructuring-assignment-to-assign-variables-from-arrays has an issue.
I feel like the challenge examples on these two problem sets don't match the code you're required to create.
For Assign Variables from Objects - This one may honestly just need a reminder that strings have a length property that can be accessed similarly to objects, which may make it easier to come up with the answer. However, even knowing that it still confuses me. The example shows you :
const { x : a, y : b, z : c } = voxel // a = 3.6, b = 7.4, c = 6.54
Which could then (with a reminder of string's length property) hint at how to write out the answer....however in the set up code provided, it wants to console log length, which - can you write
{length: length}
? Or do you have to assign length to a new variable, which then the final line you're not meant to change would be incorrect? Or could you simply do const {length} = greeting
and it would save the value of the length? For being the first challenge on destructuring, I think it's super confusing to be shown an example of an object and then be asked to work with a string, especially since (at least in the beta) I don't think there's anywhere that it talks about how a string has a property that acts similarly to an object. Perhaps I'm misremembering or misunderstanding something, though.
For Assign Variables from Arrays - This example one doesn't seem to match the challenge code at all. The example talks about using commas to get to a certain index in an array so you can assign a value in that manner. But then you're given two variables, neither in an array, and asked to swap their values? It just doesn't seem to match the example you're given.
Both challenge examples are worded well and make some sense as you're reading them...it's just that the problems you're asked to code don't seem to match the examples at all, at least to a beginner's perspective who's never worked with ES6 before and is likely relatively new to JavaScript. Just something I thought I should share in case others had wondered about the same thing. It's entirely possible I just missed something that should have shown me how to solve them and if that's the case I apologize and this can be closed.
They currently haven't written adequate tests for them yet. Guess we will just have to wait I'm afraid. https://github.com/freeCodeCamp/freeCodeCamp/issues/12698
Agreed, using "length" as a variable is confusing when a built in function is also called length.
The following code worked for me:
const [string1] = greeting;
const len = string1.length;
console.log(len);
const source = [1,2,3,4,5,6,7,8,9,10];
function removeFirstTwo(list) {
"use strict";
// change code below this line
const [x,y,...newlist] = list;
console.log(newlist);
// change this
// change code below this line
return newlist;
}
const arr = removeFirstTwo(source);
console.log(arr); // should be [3,4,5,6,7,8,9,10]
console.log(source); // should be [1,2,3,4,5,6,7,8,9,10];
This fails the "destructuring was used." test.
const source = [1,2,3,4,5,6,7,8,9,10];
function removeFirstTwo(list) {
"use strict";
// change code below this line
const [,,...arr] = list; // change this
// change code below this line
return arr;
}
const arr = removeFirstTwo(source);
console.log(arr); // should be [3,4,5,6,7,8,9,10]
console.log(source); // should be [1,2,3,4,5,6,7,8,9,10];
This also failed the "destructuring was used." test.
I need help please. I have checked my code over and over again, and it says the same thing destructuring with reassignment was used, but I'm pretty sure it should pass that test. Here is my code.
const AVG_TEMPERATURES = {
today: 77.5,
tomorrow: 79
};
function getTempOfTmrw(avgTemperatures) {
"use strict";
// change code below this line
const {tomorrow:tempOfTomorrow} = AVG_TEMPERATURES; // change this line
// change code above this line
return tempOfTomorrow;
}
console.log(getTempOfTmrw(AVG_TEMPERATURES)); // should be 79
Hi=)
const AVG_TEMPERATURES = {
today: 77.5,
tomorrow: 79
};
function getTempOfTmrw(avgTemperatures) {
"use strict";
// change code below this line
const {tomorrow:tempOfTomorrow} = avgTemperatures; // change this line
// change code above this line
return tempOfTomorrow;
}
console.log(getTempOfTmrw(AVG_TEMPERATURES)); // should be 79
Ah, I see. Thank you.
Hi=)
const AVG_TEMPERATURES = { today: 77.5, tomorrow: 79 }; function getTempOfTmrw(avgTemperatures) { "use strict"; // change code below this line const {tomorrow:tempOfTomorrow} = avgTemperatures; // change this line // change code above this line return tempOfTomorrow; } console.log(getTempOfTmrw(AVG_TEMPERATURES)); // should be 79
Ouch! I have been wondering what could be possibly wrong. Thanks
Most helpful comment
Hi=)