This forum is now read-only. Please use our new forums! Go to forums

0 points
Submitted by tony de araujo
about 9 years

Do Not put quotes in "myCountry"

Hi fellows, Please do not wrap a variable in quotes.

This seems to be a common problem.

Once a word has been declared as a *variable* 
it becomes a ' reserved'  word.

If you wrap it in quotes it loses the variable power because it becomes just a string of characters.

Examples:

var myCountry = "USA"; 
console.log(myCountry.length);
console.log(myCountry.substring(0,3));
  • “USA” is wrapped in quotes because it is a string of characters.
  • myCountry should not take quotes because it is a variable.

A variable is a memory location where we can save data.

Another example:

var myNumber = 333;
  • Although 333 is data just like “USA”, it does not get wrapped with quotes because it is a number. Only strings of characters get wrapped in quotes.

If I write “333”, the value becomes a string of characters, 3 being the character. The problem with this is that it can not be used in math.

Hope it makes sense.

Answer 55115b5e51b8872fc70020f4

68 votes
Best answer

Permalink

You’re welcome, everyone! It is a pleasure to be able to assist you and learn from all of you as well! Cheers!

points
Submitted by tony de araujo
about 9 years

53 comments

ogrle about 9 years

I’ve tried your method, but still I get Oops, try again. It looks like you didn’t log the length of myCountry to the console.

tony de araujo about 9 years

Try refreshing your browser with CTRL f5 if you still have a problem please post your code on the big window at the bottom of this page.

Carlotta McGuire almost 9 years

it works thanks

kennedymatt94 almost 9 years

Yes, refreshing the browser solved the problem. I had the same issue

mcdonaldygmail.com almost 9 years

Thanks. That helped a lot.

THanks

Seeplusplus23 almost 9 years

Thanks, thought I was doing something wrong for half an hour. The refresh really worked.

aachebe1029 almost 9 years

this really works thanks :)

Abhishek Bhagat almost 9 years

thanks

Rahman.Mumar almost 9 years

Thank you for the clarification

M-Withershins almost 9 years

Thank for your explanation and now i know why my code can’t pass!

mrhonda almost 9 years

Thanks! That was exactly what I needed!

Briana Alyse almost 9 years

Thanks a lot this one section frustrated me more than any other section!

Cwhit23 almost 9 years

Thank you so much, couldn’t find what I did wrong this helped.

Eddie S almost 9 years

Thank you so much for the help!

mastercoder78 almost 9 years

thank you

Lucifer Fire (Minecraft) almost 9 years

// Declare a variable on line 3 called // myCountry and give it a string value. myCountry = “India”

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

Lucifer Fire (Minecraft) almost 9 years

myCountry = “UK” console.log(myCountry.length); console.log(myCountry.substring(0,3) );

Clickfind almost 9 years

Thanks very much, had struggled whilst there is a forum which is very helpful.Almost gave up.

MitaliChawla almost 9 years

why we write capital C in myCountry , capital A in myAge etc.

Tishko Kurdish over 8 years

thanks alot

sam sharkey over 8 years

Thanks, helped a lot.

Amit Gupta over 8 years

Thanks Tony! :) ! It is Called ‘camelCasing’ @MitaliChawla wiki-link: https://en.wikipedia.org/wiki/CamelCase

ljgilbert over 8 years

Many thanks

Anoop kumar over 8 years

thanks

Sarah over 8 years

Thanks Tony.

karishmachudasama over 8 years

omg thank you!

BlitzStarGaming over 8 years

Thanks Tony!

Evangel over 8 years

Thanks Tony

carmosen over 8 years

Thank you for your help sir :)

Trevorclingman over 8 years

you helped alot thank you

dhaniljith over 8 years

thanks

thunderwayne over 8 years

thanks :D

Cullen Wells over 8 years

go chinese

Cullen Wells over 8 years

keep up the good work leng lee

Tutul over 8 years

Thanks

Fábio Henriques over 8 years

Thank you

Mohammad Daud Ibrahim over 8 years

Thanks “ tony de araujo “

thanks!!!

SamanthaGeorge over 8 years

I can’t get it to work, keeps tellin me that I have a problem in my synax

DomoGenisis over 8 years

hahahhaha

Darian Morgan over 8 years

Appreciate it!

Alice over 8 years

Oh my goodness, thank you :) Now I am actually getting it all done haha

ishidas1134 over 8 years

Thank you sooooooo much for a crystal clear answer!!!

Shaimaa Hamdy over 8 years

I’ve been trying but nothing happened then I refreshed my browser so it worked.thanks

krishflames over 8 years

THANK YOU SO MUCH! AND DO HELP US FURTHER.

tony de araujo over 8 years

Hey, you’re welcome guys! Glad to be able to help, thanks.

Max Olejarz over 8 years

BANANA

ItzHazza123 over 8 years

i love this

ctaylo30 over 8 years

Thank you so much!! For some reason I was putting myCountry.substring(0,8) on the second line when I should have been putting .length. …lol

Samantha Linares over 8 years

THANK YOU SO MUCH!!!!!!!!!!!!

castiq over 8 years

Thanks! this helped a bunch

heyy_its_Jessica over 8 years

@ctaylo30 I was doing the exact same thing!

Answer 55299cf7937676d3f10004db

11 votes

Permalink

Hey, thank you for the response, I was going crazy. If this is a common issue, might I recommend changing the Hint for it. The hint honestly offers little to no explanation for this particular problem. :)

points
Submitted by Spencer Kerr
almost 9 years

2 comments

Briana Alyse almost 9 years

The hint is on part 24/28 of this section in the introduction for “Variables”. I actually had a problem with this section and found help in this forum, but once I went back to review things I found the hint that was given.

nithinlalcoder over 8 years

thanks man it was very usefull

Answer 5504cfaa95e378bf1c00526f

8 votes

Permalink

Make sure the C in myCountry is capitalized as well ;)

points
about 9 years

5 comments

fayebradley29 almost 9 years

hey

MitaliChawla almost 9 years

but why?

unathi1 almost 9 years

thank you guys!!! I almost spent the whole night trying to figuer this out

Balder94 over 8 years

that is just a style choice though right ?

Sahar over 8 years

For the purposes of the lesson, you’re going to have to type the variable exactly as the lesson asks. If you declare the variable as mycountry, you might’ve well said “fruit” or “JohnTravolta” JS is super literal, the lessons are super literal. It’s good practice.

Answer 553f6c70d3292f9c210001d5

7 votes

Permalink

var myCountry = “New York”; console.log(“New York”.length); console.log(“New York”.substring(0,3));

points
Submitted by Maneesh singh
almost 9 years

7 comments

MasSuarjana over 8 years

Thanks you :)

gopi24f over 8 years

thanks

Chriswatt2 over 8 years

Thank You!

speedysid over 8 years

Nice. That was bugging me for ages.

Martin Mutisya over 8 years

cheers mate. the thing has really taken some of my time to crack it up.

DomoGenisis over 8 years

ahahahahahhahahahahhahaa

Criss Laurente over 8 years

Thank You! c:

Answer 552ce6c59113cb224e000541

5 votes

Permalink

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

here is my code lines,

var myName= myCountry;
console.log(myName);

and this

var name= myCountry;
console.log(myCountry.length);
console.log(myCountry.substring(0,3));

but i got this error

ReferenceError: myCountry is not defined

let me guide on this.

points
Submitted by umair ahmad
almost 9 years

4 comments

bonkotronko almost 9 years

var myCountry= “name of your country”; console.log(myCountry.length); console.log(myCountry.substring(0,3));

Fabian Landeros almost 9 years

needs quotes

Shimansh Kothari over 8 years

Thank You!

argumentik over 8 years

I’ve made it like this and it got run:

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

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

Answer 553944f595e3780a880001e0

1 vote

Permalink

Thanks

points
Submitted by GoingMainStreet
almost 9 years

1 comments

Michael Dessler over 8 years

kdjasd

Answer 557aa2119376767c5e000025

1 vote

Permalink

dees nuts ha got he

points
Submitted by jordansharp
almost 9 years

Answer 560004d951b88757ed000321

1 vote

Permalink

bananan

points
Submitted by Max Olejarz
over 8 years

Answer 5514888d76b8fe505c001715

0 votes

Permalink

Thanks

points
Submitted by Don King
about 9 years

Answer 551826ae76b8fe81bc003a18

0 votes

Permalink

Thank!. that cleared it up for me

points
Submitted by mobileappmogul
almost 9 years

1 comments

fayebradley29 almost 9 years

well done

Answer 55182764e39efea2f000399e

0 votes

Permalink

My code looks exactly like yours, Tony, but I get the “Oops, try again” message every time.

Here is my code: var myCountry = “United States of America”;

console.log(“myCountry”.length);

console.log(“myCountry”.substring(0, 3));

My variable assignation isn’t “catching.” My code evaluates to: 9 myC

points
Submitted by tavhienda
almost 9 years

3 comments

tony de araujo almost 9 years

Hi, read the title of my post. That is your problem. Remove the quotes from “myCountry”. If you still have problems after that, refresh the browser with CTRL + f5 ( or CMD + r if on a MAC). Good luck!

tavhienda almost 9 years

Yikes - I was only looking at where I was assigning the variable. Thanks!

tony de araujo almost 9 years

:))) glad to know it worked out for you!

Answer 551b6fcd937676e4f3000793

0 votes

Permalink

the answer help’s

points
Submitted by aviclop
almost 9 years

Answer 5524404251b887e3bb000093

0 votes

Permalink

The following text is our instructions:

“For example: var myName = “Steve Jobs”; myName.substring(0,5) Look at the second line above. You have asked the computer to swap out myName and swap in Steve Jobs, so myName.substring(0,5) becomes “Steve Jobs”.substring(0,5) which evaluates to Steve.”

So see why we are doing what we do now? Thanks.

points
Submitted by pattieanneusa
almost 9 years

Answer 5525d25576b8fe462f0005cc

0 votes

Permalink

This is what I am doing for code:

// Declare a variable on line 3 called // myCountry and give it a string value. var myCountry = “Narnia”;

“Narnia”.substring(0,6);

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

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

It keeps telling me: It looks like you didn’t log the length of myCountry to the console.

I am getting so frustrated; I am just not seeing what I’m doing wrong.

points
Submitted by April McMillan
almost 9 years

6 comments

April McMillan almost 9 years

I tried it with all “myCountry” and all “Narnia” - so (0,9) and (0,6) - and then with and without quotes…. it just keeps saying it’s wrong

April McMillan almost 9 years

HA - I needed to use the word “length” - LOL all that time spent for something so simple :/

LazyNerd almost 9 years

mine is same as yours…but i’m still getting error(ReferenceError: myCountry is not defined) var myCounrty = “Pakistan”; console.log(myCountry.length); console.log(myCountry.substring(0,3));

MitaliChawla almost 9 years

Write like this var myCountry = “Pakistan’ ;

dstewart15 almost 9 years

im getting console.log is not a function

maki2015van over 8 years

I got stuck on the same thing for about an hour……. try this it worked out for me. // Declare a variable on line 3 called // myCountry and give it a string value. var myCountry = “Makicar”;

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

Answer 552ce81b76b8fe180b000059

0 votes

Permalink

great post, i got the answer of my error. :)

thats wonderful. i spend 1 hr on this exercise.

points
Submitted by umair ahmad
almost 9 years

Answer 5557904e51b887f186000540

0 votes

Permalink

Thanks so much! This helped me out alot!! You have no idea!

points
Submitted by JulieRoze
almost 9 years

Answer 5572b855d3292f2f5000050f

0 votes

Permalink

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

var myCountry="krypton";

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

console.log("krypton".length);

// Use console.log to print out the first three letters of myCountry.

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

output: 7 kry

how i get output.its strange??

points
Submitted by swali1
almost 9 years

3 comments

swali1 almost 9 years

*did

Ekanem over 8 years

shouldnt it be console.log(myCountry.length); ?

prashant.gharti over 8 years

var myCountry = “New York”; console.log(“New York”.length); console.log(“New York”.substring(0,3)); Try this one

Answer 557c61d4d3292fb5e30002a4

0 votes

Permalink

thank you Forum

points
Submitted by cmui98
almost 9 years

Answer 5599fd55d3292f68020005fe

0 votes

Permalink

var myCountry = “USA”; console.log (myCountry.length); console.log (myCountry.substring (0,3));

no quotes around myCountry. I got 3, USA

points
Submitted by Glenn Bady
over 8 years

Answer 55b8d3fde39efedd1d0002bb

0 votes

Permalink

this is useful, thank you.

points
Submitted by Safiya
over 8 years

Answer 55be04b5937676dda60005d7

0 votes

Permalink

Help!

**// On line 2, declare a variable myName and give it your name.
var myName = "Beka";
// On line 4, use console.log to print out the myName variable.
console.log("Beka")
// On line 7, change the value of myName to be just the first 2 
// letters of your name.
var myName = "Salmoorbek";
// On line 9, use console.log to print out the myName variable.
console.log("Salmoorbek")
**

It seems to have written as it is, I do not understand what it was, whether knows everything about this is not right!

points
Submitted by SalmoorbekTokoev
over 8 years

Answer 560241bd51b887c460000156

0 votes

Permalink

// Declare a variable on line 3 called // myCountry and give it a string value. var myCountry console.log (mycountry = USA) // 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 still not working

points
Submitted by Paul Rochatka
over 8 years

Answer 5605b2b69113cb858400022e

0 votes

Permalink

Thank you for the help. I was stuck on this script for a month now. Writing codes is fun

points
Submitted by Alvin Detoya
over 8 years

Answer 55d89a08e39efe7ebb000164

-2 votes

Permalink

var myCountry = “New York”; console.log(“New York”.length); console.log(“New York”.substring(0,3));

Try this one..

points
Submitted by prashant.gharti
over 8 years

1 comments

You should NEVER retype the value once the value has been declared. Always retype the variable.