You will often need to know how many characters are in a string.
For this you will use the .length
property. Here's an example:
var example = 'example string';
example.length
Make sure there is a period between example
and length
.
The above code will return a number for the total number of characters in the string.
Create a file named string-length.js
.
In that file, create a variable named example
.
Assign the string 'example string'
to the variable example
.
Use console.log
to print the length of the string to the terminal.
Check to see if your program is correct by running this command:
javascripting verify string-length.js