My code is using Destructuring Assignment and the function is working but when i Run it: “destructuring with reassignment was used” was not checked
Is this a bug or I just have the wrong code? (still learning)
Cheers,
Szabi
Your code so far
function getLength(str) {
"use strict";
// change code below this line
const {length : length} = str;// change this
let len = length;
// change code above this line
return len; // you must assign length to len in line
}
console.log(getLength('FreeCodeCamp'));
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36.
So in my first(not corrected) code, i used an extra code: let len = length;
but i still used destructuring assignment, just not the cleanest way. On the Lesson side the “destructuring was used.” was with a red circle with an “X” instead of it being checked.
It works with my corrected code, but with the old one it does not. I’ve tryed in chrome dev tool and it works normally. The reason the lesson did not accept it is because I did not write the code exactly as it was intended. Thanks for the help, I have an issue with a similar case with “ES6: Use Destructuring Assignment with the Rest Operator to Reassign Array Elements” but i will make a separate post about that. Thank you again
Thanks for this, it’s been bugging me for hours… However, I have one question; Which part of the code is actually calculating the length of the string?
I was expecting a str.length; in there or something similar.