More Variable Practice: How to solve it?


#1

This is what i wrote. I'll put the words in bold that i used:

// Declare a variable on line 3 called
// myCountry and give it a string value.
var myCountry: United Kingdom

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

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

Editor: Oops, try again. There was a problem with your syntax.

Syntax: SyntaxError: Unexpected token :

Where is that colon? Please tell me a solution.


#2

That line has the : problem. You should use an = to assign value when coding in JavaScript.


#3

Let me try that. Thanks


#4

I tried it with a few adjustments:

// Declare a variable on line 3 called
// myCountry and give it a string value.
var myCountry = "United Kingdom"

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

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

Editor:Oops, try again. It looks like you didn't log the length of myCountry to the console.

The print of the letters are right. The first one is the whole word and the second one is "uni". What is the mistake?


#5

The first thing printed should be a number, the number of characters in myCountry. You will need to use .length instead of .substring.


#6

Oh ok ill try that. Thanks


#7

I tried it:

// Declare a variable on line 3 called
// myCountry and give it a string value.
var myCountry = "United Kingdom"

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

// Use console.log to print out the first three letters of myCountry.
console.log("Uni".length);

Still not working


#8

That's because the exercise wants you to use the variable myCountry.