Having problem with getting started 23


#1

console.log("january".substring(0,1,2) );
console.log("Melbourne is great".substring(0,1,2,3,4,5,6,7,8,9, 10) );
console.log("Humburgers".substring(3,4.5.6,7,8,9) );

this is the code


#2

i just corrected your errors

console.log("january".substring(0,1,2) );
console.log("Melbourne is great".substring(0,1,2,3,4,5,6,7,8,9, 10) );
// you had an error here
console.log("Humburgers".substring(3,4,5,6,7,8,9) );

#3

Hi @hansdeveloper_555a30 I'm agree with @arccoder77254 , you have to do know what the substring() method extracts between "start" and "end", and not including "end" itself.

 console.log("january".substring(0,3)); //will return jan

Reason : index[3] of "january" is "u" and it's not include.

Do it for your other string.

Hold on :wink:


#4

I have a similar problem:

The instructions state that the numbering starts at 0.
So for the word "Hello" it looks like this:
1st - H - substring position 0
2nd - E - position 1
3rd - L - position 2
4th - L - position 3
5th - O - position 4

When the assignment asks to log a substring "Jan" out of "January" it should follow the same sequence:

1st - J - position 0
2nd - A - position 1
3rd - N - position 2

By this logic my code needs to look like this:
console.log("January" .substring(0,2));
But it only returns "Ja".

What am I missing?

Thanks!


#5

@mikeev85 when you use:

console.log("January" .substring(0,2));

it will start pulling letters from the string at position 0 and it will stop at position 2, meaning that position 2 won't be pulled. So it will only pull position 0 ("J") and position 1 ("a"). In order to include position 3 ("n") you would need to do

console.log("January" .substring(0,3));

Think if it as going from the first number to < the last number, not <= the last number.


#6

This makes sense. Thank you for the response @freginold!
I must've missed that in the explanation.