My Code on 26 won't work


#1

// On line 2, declare a variable myName and give it your name.
var myName = "Harry";
// 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,2);
// On line 9, use console.log to print out the myName variable.
console.log(myName);


#2

It should be substring(0, 3).


#3

Maybe, on line 7 change it from
myName = myName.substring(0,2);
to
myName = "Ha"


#4

Tried both still doesn't work.


#5

I copy and pasted your code in and it worked. I guess clear everything you have and repaste it.


#6

Screenshot please.


#7

While that does get you the first two letters of your name, we are trying to learn programming here and that means telling the computer how to do it for us.

What if the next user was named Fred? When your program ran, his name would be shortened to "Ha", and that would be almost certainly be confusing for him. :green_heart:


#8

// 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".substring (0, 2));

try this if nothing else worked


#9

That doesn't change the value of myName. To change the value you would need to begin like this:

myName =

That is going to print the first to characters of "myName", which would be:

my

Is that what you had in mind?