Basic JavaScript - Find the Length of a String

Tell us what’s happening:
Describe your issue in detail here.

Not sure what I am missing?

Your code so far

// Setup
let lastNameLength = 0;
const lastName = "Lovelace";

// Only change code below this line
lastNameLength = lastName;
console.log("lastName".length);

Challenge: Basic JavaScript - Find the Length of a String

Link to the challenge:

You want to set the lastNameLength variable to the number of characters of lastName. Console.log will not achieve this, although it will provide you with the length of the variable if you wanted to check your solution. To make things more simple, maybe try the problem without console.log and just focusing on setting the length with .length. You want to add .length to the appropriate part of the “lastNameLength = lastName” statement, so as to assign the number of characters of the lastName TO the lastNameLength variable.

Maybe you are misled by the WRONG console information.

console.log("lastName".length);       // misleading, it doesn't return your variable length
console.log(lastName.length);         // CORRECT
const lastName = "Abc";            
console.log("lastName".length);       // return "8", it counts hard-coded string of 'l,a,s,t,N,a,m,e'
console.log(lastName.length);         // return "3", it counts variable of 'A,b,c'

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.