Lesson 25 More Variable Practice Help


#1
  1. // Declare a variable on line 3 called
  2. // myCountry and give it a string value.
  3. var myCountry = "South Africa"

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

  5. console.log("myCountry".length);

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

  7. console.log("myCountry".substring(0,4));

why on earth am i getting this wrong? pease help me asap


Lesson 25 More Variable Practice Help
#2

When you use quotes you are indicating a string, not a variable.

"myCountry".length is 9
myCountry.length is 12

Do you see the difference now?


#3

oh ok thank you very much. I figured that out in the end.


#4

Can somebody please tell me what's wrong with my code. I am stuck.

// Declare a variable on line 3 called
// myCountry and give it a string value.
var 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));


#5

You want the length property of myCountry so you should put your .length so that it is attached directly to myCountry.


#6

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