Below is my code: please what is wrong with the code!
var lastNameLength = 8;
var lastName = "elamin";
lastNameLength = lastName.length;
Below is my code: please what is wrong with the code!
var lastNameLength = 8;
var lastName = "elamin";
lastNameLength = lastName.length;
This is the url of the challenge below
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/find-the-length-of-a-string
You need to use the .length
property of strings. You don’t assign the length of the string, the length of string is generated once you create the string.
Please help with correct code I really stuck!
// Example
var firstNameLength = 0;
var firstName = "Ada";
firstNameLength = firstName.length;
///outputs: 3
I think you should start over. Then, look at the example and try to figure out what you need. You don’t need much and only need to add one word and a period.
This is the code:
var lastNameLength = 8;
var lastName= “elamin”;
lastNameLength = lastName.Length;
But it’s showing
lastNameLength should be equal to eight.
You weren’t supposed to change var lastName
or any of the vars for that matter. Trust me when I say start over.
Or if you’re hesitant to hit the reset button:
// Example
var firstNameLength = 0;
var firstName = "Ada";
firstNameLength = firstName.length;
// Setup
var lastNameLength = 0;
var lastName = "Lovelace";
// Only change code below this line.
lastNameLength = lastName;
I have start over but it’s still say lastNameLength should be equal to eight. below is the code:
// Example
var firstNameLength = 0;
var firstName = “Ada”;
firstNameLength = firstName.length;
// Setup
var lastNameLength = 0;
var lastName = “Lovelace”;
// Only change code below this line.
var lastNameLength = 8;
var lastName = “Ada”;
lastNameLength = lastName.length;
Remember what I said? Starting from the very beginning, the only thing you have to do is add one word and a period and you will be done.
You don’t need to add other variables, they are already set up for you.
Let me see if I can walk through the example:
var firstNameLength
is initiallized to 0
;
var firstName
is equal to “Ada”
Now we are taking firstName
and accessing the .length
property of strings (because firstName
holds a string value). This is done by firstName.length
and by doing this we will get the length of the string, as a number, that is stored in firstName
.
Then we put that value into firstNameLength
.
Thank you a lot, I have passed the challenge.