Help ! Java Script : Change variable values Lesson26


#1


Oops, try again. It looks like you didn't log your whole name to the console.


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


#2

Should be:

// On line 9, use console.log to print out the myName variable.
console.log (myName);

You just need to log variable's value not the length.


#3

Don't get it .

I tried this :
console.log( myName( 0,2 ) );

But it's not the right answer.
Can U help me ? :slight_smile:

Thx


#4

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

#5

Still enable to pass this step .
What's wrong ? > <"

Can u help me , plz

THX


#6

Try it, I tested this code and passed the lesson:

// On line 2, declare a variable myName and give it your name.
var myName = "ZiYi";

// On line 4, use console.log to print out the myName variable.
console.log ( myName ); // here you need just to print myName variable

// On line 7, change the value of myName to be just the first 2 
// letters of your name.
console.log( myName.substring(0,2) );

// On line 9, use console.log to print out the myName variable.
console.log ( myName );

#7

It works .
U help me a lot , THX verrrrry much . Y^0^Y


#8

It doesn't work in the sense that it doesn't change the value of myName to be just the first 2 letters. It only passes the exercise because the code that is checking your code is not doing a good job.

With the following line of code you are logging the first two letters of myName but you are not changing the value of myName.

console.log(myName.substring(0,2));

If you want to change the value of myName then you'll have to start out like this:

myName =

and put whatever new value you want myName to have on the right hand side of the =

Do you see how that works now?


#9

Thank you for your reply! It helped me to understand this lesson better.


#10

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