Lesson #23-why is my string incorrect?


#1

I have the following to pull out just Jan in "January"

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

but I keep getting an Oops..didn't select correct substring for January
if I make this a comment by adding // in front of console, the rest of my coding works..


#2

Can you post all of your code? It will be easier to pinpoint any possible errors.


#3

You said:

I have the following to pull out just Jan in "January"

At first, I thought you were printing Janu.

You've requested to extract a substring starting at index 0 through 3. If you count from zero to three, you will end up with four characters. J is 0, a is 1, n is 2, and u is 3. However, according to specifications listed on Mozilla Developer's Network, the ending range is not included, so it would only print index 0 through 2.

After seeing pbawler's response, I decided to run both your code and pbawler's... and the below does print out "Jan". I also do not receive any errors from the console or Codecademy.

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

Do you mind sharing your complete code as it is listed on the script.js window, as well as the output of the Console?


#4

same problem here.......the following is my code
console.log("january".substring(0,3));
console.log("melbourne is great".substring(0,13));
console.log("Hamburgers".substring(3,10));

from the output windows i can see what is printed is correct,so whats the problem


#6

console.log("january".substring(0,3));
console.log("melbourne is great".substring(0,13));
console.log("Hamburgers".substring(3,10));

The evaluation on each string is case sensitive.
After changing "january" and "melbourne" on your code, I was able to proceed to the next lesson.

console.log("January".substring(0,3));
console.log("Melbourne is great".substring(0,13));
console.log("Hamburgers".substring(3,10));

#7

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.