Hvad er det der ikke virker? Er der en fejlbesked? Skriver tutorialen noget til dig? Et eller andet? Det er svært at hjælpe dig videre uden nogle detaljer at gå ud fra.
Der bliver skrevet det her ;
5. Substrings
We've learned a few ways to manipulate numbers. What about manipulating strings?
Sometimes you don't want to display the entire string, just a part of it. For example, in your Gmail inbox, you can set it to display the first 50 or so characters of each message so you can preview them. This preview is a substring of the original string (the entire message).
Code:
"some word".substring(x, y) where x is where you start chopping and y is where you finish chopping the original string.
The number part is a little strange. To select for the "he" in "hello", you would write this: "hello". substring(0, 2);
Think of there being a marker to the left of each character, like this: 0-h-1-e-2-l-3-l-4-o-5.
If you chop at 0 and again at 2 you are left with just he.
More examples:
1. First 3 letters of "Batman"
"Batman".substring(0,3)
2. From 4th to 6th letter of "laptop"
"laptop".substring(3,6)
Find the 4th to 7th letter of the string "wonderful day".
Remember to start counting from 0. There is no need to use console.log as you are not asked to print it out!
Du kan se
her ;