third test case: destructuring with reassignment was used
Your code so far
function getLength(str) {
"use strict";
// change code below this line
var o = {leng: str.length};
const { leng : len } = o; // change this
// 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/68.0.3440.106 Safari/537.36.
@shimphillip is exactly right. Its the intermediate step of assigning the value into your object o, then using that to populate len, that is causing your code to fail. Instead, simply use str to populate len directly, using destructuring .
Thank you guyz for quick response. But I m still not able to figure out the one line code. See this below code is laso not passing the third test case.
function getLength(str) {
“use strict”;
// change code below this line
const {l: len} = {l: str.length}; // change this
// change code above this line
return len; // you must assign length to len in line
In first example, you’re assigning len a value of a property length of the string named ‘str’. Thus when you assign str, it finds its length. And how you’re gonna check that? Here’s how: Instead of using string str put some other string in function with its own, different value and console log it.
standard:
function getLength(str) {
"use strict";
var ttt="ojha";//another string
// change code below this line
const {length : len}=ttt;//find a length of string
console.log(len); //display it at console
return len; // you must assign length to len in line
}