27. Conclusion Part 1



On line 1, create a variable myColor and give it a string value.
On line 2, print the length of myColor to the console.

var "myColor"= "red"

It's saying "Oops, try again. There was a problem with your syntax."

Please Help!


Hey there.

Variable names is JavaScript and many other languages are written in plain text. That is text without quotes or anything syntactically unimportant surround the variable.

So "myColor" would need to become just myColor.

There's one more thing.

In the console.log() parentheses you'll want to use the variable name like before and then .length. Not "DD" as that is not valid in this context.


Sorry but I am still stuck :sob:


i tried taking the quotes off but it said thisOops, try again. It looks like 'myColor' on line 2 was not defined before it was used. This means either you need to define it, 'myColor' is spelled incorrectly or you need quotes around 'myColor'.


Okay lets try it this way then..

You wrote

var "myColor"= "red"

What you should have instead is:

var myColor = "red";

Why? because variable names in JavaScript are written this way. var myColor is a variable. It's currently storing "red" as it's value. When you put quotations around characters like red for example it is known as a String datatype. Therefore we can not apply this to a variable name because we're not trying to store a String inside of a String.

For your last line you wrote:


It should be showing as:


Why? Because the exercise wants us to learn how to use our variables and their values. By putting .length after the variable name we're going to get the length of the string we are testing. Console.log() will print that and show us how many characters are present in the myColor variable. It should be 3 in this case because red contains 3 characters.

I hope that's more understandable now.


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