27. Conclusion Part 1


#1


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


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"
console.log("DD".length);

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

Please Help!


#2

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.


#3

Sorry but I am still stuck :sob:


#4

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'.


#5

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:

console.log("DD".length);

It should be showing as:

console.log(myColor.length);

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.


#6

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