"wounderful day".substring(3,7);

what is wrong with this code?


write wonderful
ok?? :slight_smile:


syntax is write... output should be "derf"
if you want to see output..try this
console.log("wonderful day".substring(3,7));


Except that the numbers don't match up to what the example explains. If "W" is 0, then "f" should be 6, not 7 according to the example:

Each character in a string is numbered starting from 0, like this:

0 1 2 3 4
| | | | |
h e l l o
The letter h is in position 0, the letter e is in position 1, and so on.

Therefore if you start at position 0, and slice right up till position 2, you are left with just he

but the examples below it are like the code, with the numbers being their positions if you start numbering at 1 and not 0.


I think it's better way to remember
first substring number is array position
second substring number is string position



Hey, are blank spaces counted as numbers when using substrings in Javascript?


They are counted as characters, just like numbers and letters are.