25.More variable practice.Can you please help me?


#1

// Declare a variable on line 3 called
// myCountry and give it a string value.
console.log(myCountry)
var myCountry = "New York";

// 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,2));.


#2

What is the problem you're trying to fix? Undefined variable?


#3

It's telling me to declare a variable on line 3 called myCountry as you can see i id it.The second one is is telling me use the console.log to print out the length of the variable i did that as well.And the third one is telling me to print out the first three letters of myCountry i did that and it's telling me Oops, try again. It looks like 'myCountry' on line 3 was not defined before it was used. This means either you need to define it, 'myCountry' is spelled incorrectly or you need quotes around 'myCountry'.


#4

Can you find anything wrong and help me?


#5

Ok, so you just need to remove the current line 3, where you try to print myCountry. console.log(myCountry)

Because you try to print it out on the console before you define it (on line 4 - var myCountry = "New York";) it gives you that error.

You should be all set! :smile:


#6

like this?

// Declare a variable on line 3 called
// myCountry and give it a string value.

var myCountry = "New york";

// 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,2));.


#7

Exactly like this! Also, when you post code on here you can surround it with three backticks (`) to get it all pretty and easy to read.


#8

ok but now there are telling there is a problem with your syntax?


#9

Read really carefully through your code. Maybe it's the dot (.) on the last line after the semicolon (;) ?


#10

well i removed it but it's telling me the same thing.


#11

i tried to remove the brackets on the current line 3 on "var myCountry = "New York";


#12

console.log("myCountry")
var myCountry = "New York";

// 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));
That should fix it if you still need help you do need line three and it needed quotations. Also the was a period(.) at the very end.


#13

console.log("myCountry")
var myCountry = "New York";

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

// Use console.log to print out the first three letters of myCountry.
console.log("New York".substring(0,3));
i had it wrong the first time this works..


#14

thanks man u rock :sunglasses:


#15

I'm also having little trouble here.
yes it works this way if you type console.log("New York".length); but as i understand the point is to use var myCountry to run it, instead of type out the name yourself.
so i understand the point is to do it so... console.log("myCountry".length); instead of... console.log("New York".length);
but its not working like this..
if i type out New York then whats the point of variable at all??
i hope someone can explain little.
Thanks a lot up front and i wish all happy coding day :smile:


#16

Ok, i figured it out.
console.log("myCountry".length); I used " " and that made it not read it as variable.


#17

so this is my code but its not working I need help pls. I cant tell whats wrong

//Declare a variable on line 3 called
//myCountry and give it a string value
var myCountry = "New York";

// 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));

its saying that I didn't log the length of myCountry to the console


#18

nvm I figured it out I used " " on the variable my country so the computer did not see it as a variable


#19

In the future you should probably make your own topic. This is a Q&A forum so there's no shame in doing so and I am sure many others here would appreciate that. I've seen them scold o.o

Gj figuring it out!


#20

thankyou and how do I make my own topic and how do I post stuff?