26 Change variable values


#1

Hi!
I've got problem with exercise 26.
That's my code:

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

In result window it prints everything correctly, but CA prints error"Oops, try again. It looks like you didn't log the first 2 letters of your name to the console".
What did i wrongly?


#2

Well, try this

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


#3

Thanks for your help :smile:
Correct one is the same as yours except line 7:

myName=myName.substring(0,2)


#4

on line 7 please use
myName = myName.substring(0,2);