Tell us what’s happening:
Describe your issue in detail here.
Hi all I wonder if anyone could help me with this, this is my code so far, I dont understand the error, can anyone help please?
this is the challenge :
Use the `.length` property to set `lastNameLength` to the number of characters in `lastName`.
**Your code so far**
let lastNameLength = 0;
const lastName = "Lovelace";
// Only change code below this line
lastNameLength = lastName;
lastNameLength = 8;
Your browser information:
User Agent is:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/184.108.40.206 Safari/537.36
Link to the challenge:
the challenge expects you to give lastNameLength the number of characters by using the .length not typing out the number.
The console would calculate the number not you.
so to give d lastNameLength the no. of characters of lastName,
you should just add .length after the variable lastName. on the 2nd to last line of the code
then you can delete the last line you with the number 8 you added
lastName is a string literal
lastName.length is a property of the string that gives us how long it is
= sign (equals) is the assignment operator which tells the computer to remember something by storing it in memory.
If I want to remember my name for eg, I would write:
let myName = “Hanaa”;
and the computer will put that literal string into memory somewhere for the duration of my program.
Okay so we want to find the length of a string.
We know that we can use the property length to do that.
If we look at the first 2 lines of code they also tell us something about the intentions of the program. Here they are:
let lastNameLength = 0;
const lastName = “Lovelace”;
This says that somewhere in memory there is a spot saved for holding the number 0
and we call that spot lastNameLength
It also says that there is a spot in memory used for holding the string “Lovelace” and this spot is called lastName
So far this program is keeping 2 values in memory.
A length currently set to 0
Obviously the length of the name is not 0 so we need to change that.
At this point we know that:
= equals is the assignment operator (we use it to store things in memory)
length is the property used to find the length of a string.
We need to combine these two ideas to get the length of the lastName and store it in lastNameLength.
So what do you think you need to do to do that?
I will try doing that
I didn’t give much thought to these concepts until I read your post… I simply pressed the required keys as if I were a keypressing monkey to solve the challenge… Maybe I should reflect more on the intentionality of the exercises as opposed to simply regurgitating recipes… Thanks for a wonderful post…