25. More Variable Practice


#1


https://www.codecademy.com/en/courses/getting-started-v2/4/2?curriculum_id=506324b3a7dffd00020bf661


It repeatedly says to me "Oops, try again. There was a problem with your syntax."


Replace this line with your code. 
// Declare a variable on line 3 called
// myCountry and give it a string value.
var myCountry = "New York"
console.log(myCountry)
// Use console.log to print out the length of the variable myCountry.
var "myCountry".length;

// Use console.log to print out the first three letters of myCountry.
var "myCountry".substring(0,2);
I don't understand what i'm doing wrong. Please help!


#2

Hi,

here is correct code for this task!

// Declare a variable on line 3 called
// myCountry and give it a string value.
var myCountry = "Sierra Leone";

// Use console.log to print out the length of the variable myCountry.
console.log(myCountry.length);

// Use console.log to print out the first three letters of myCountry.
console.log(myCountry.substring(0, 3));


#3

Thank you.:slight_smile:


#4

The main problem - it's non-compliance with the instructions to the task!

Your errors:

  • you are forgetting for a semicolon at the end of the expression! For example look at your var myCountry = "New York" (add here ";" after "New York"). Or for example console.log(myCountry)
  • In this task there was stated the following: // Use console.log to print out the length of the variable myCountry.
    ...and you write something quite different: var "myCountry".length;
    Here must be console log like this console.log(myCountry.length);

Hopefully this has helped you!


#5

This still isn't working. I did what you said to.


#6

I corrected your code:

// Declare a variable on line 3 called
// myCountry and give it a string value.
var myCountry = "New York";
console.log(myCountry);
// Use console.log to print out the length of the variable myCountry.
console.log(myCountry.length);

// Use console.log to print out the first three letters of myCountry.
console.log(myCountry.substring(0, 3));

Your code is running well now! :wink:

You can check it!


#7

var "myCountry".length; // here its wrong

because you are told to print out the length of the variable myCountry.it menas you have to print the length of the value of mycountry variable.
so you have to write

var myCountry.length; // without quotation

when you write "myCountry".length, it'll print the length of myCountry not New York(your value).

********* substring Syntax********

string.substring(start,end)

start: Required. The position where to start the extraction. First character is at index 0
end: Optional. The position (up to, but not including) where to end the extraction. If omitted, it extracts the rest of the string.


#8

thanks so helpful:grinning:


#9

A post was split to a new topic: 25. Having some issues with the variable here is the code that I am using


#10

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