freeCodeCamp / curriculum

The freeCodeCamp curriculum and lesson editor
Creative Commons Attribution Share Alike 4.0 International
81 stars 125 forks source link

ES6: Use Destructuring Assignment to Assign Variables from Objects #213

Closed nathanhannig closed 6 years ago

nathanhannig commented 6 years ago

https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/es6/use-destructuring-assignment-to-assign-variables-from-objects

Decription Use destructuring to obtain the length of the input string str, and assign the length to len in line.

I believe 'in line' should be a single word: 'inline'

nathanhannig commented 6 years ago

Overall, I feel the challenge is a little confusing as it's examples are based on an object and it is wanting you to complete the challenege on a string.

I think the examples should maybe mention you can use destructuring to grab properties also from strings, or maybe change the challenge to mimic the example a little closer.

joshalling commented 6 years ago

While I agree that the instructions are confusing, I feel like it is also good to at least try to apply a concept like this to a more specific situation.

Maybe rather than change the challenge we could add a hint to the guide. That way the camper is still being pushed to figure it out on their own, but they have a place to go for help if they get stuck.

Thoughts?

nathanhannig commented 6 years ago

Yeah I think it is important as I never thought of pulling length property of a string through destructuring.

We should probably say you can also destructure built-in property values from objects as well

const arr =  [1, 2, 3];
const { length } = arr;
console.log(length); //3

Here is a forum post of complaints: https://forum.freecodecamp.org/t/beta-feedback-es6-confusing-challenge-description-destructuring-assignment/172303

joshalling commented 6 years ago

I think you're right, as it would help to avoid the frustration described in that post. I was just worried about there being too much hand holding through this challenge. Your solution above is good because it still forces the camper to apply the reassignment of length to len.

johnkennedy9147 commented 6 years ago

I think this is a poorly written challenge. It is confusing as it relies on campers having an understanding of the difference between string primitives and string objects and how JavaScript automatically converts primitives to objects in order to apply methods or lookup properties.

Given we don't seem to cover these facets of strings in the curriculum prior to this challenge it is unfair to expect them to figure this out in a challenge that is supposed to be about learning destructuring objects.

I think we should change the challenge to explicitly use an object.

joshalling commented 6 years ago

@johnkennedy9147 In that case, we would need to update the the tests and contents of this challenge. Could we do something similar the next challenge that uses a nested object? For example:

const AVG_TEMPERATURES = {
  today: 77.5,
  tomorrow: 79
};

function getTempOfTmrw(avgTemperatures) {
  "use strict";
  // change code below this line
  const tempOfTomorrow = undefined; // change this line
  // change code above this line
  return tempOfTomorrow;
}

console.log(getTempOfTmrw(AVG_TEMPERATURES)); // should be 79
raisedadead commented 6 years ago

:tada: This issue has been resolved in version 3.2.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket: