Question 26/28


#1

On line 2, declare a variable myName and give it your name.
var myName = "Mike Izcool";
// 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);

First time ive been stuck on any of the codecademy problems. The given hint hasn't help besides the () on lines 4 and 9. Probably a fairly simple mistake i'm making. Please help


#2

Hi,

I believe you are missing brackets at line 7.

// On line 2, declare a variable myName and give it your name.
var myName = "Sial"
// 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);


#3

i changed line 7 to this

myName = (myName.substring(0,2));

but its saying that i did not log my whole name to the console.log...


#4

Thanks Sial. Me ayudo mucho tu respuesta.


#5

Equal sign is unnecessary here. Lines two and nine.

You do not want setting console.log to (myName) by equal sign. You want to use console.log() on myName variable. :smile:


#6

All, I appreciate the help, but TBH im still not getting through this problem.. This is what I have:

// On line 2, declare a variable myName and give it your name.
var myName="mitch";
// 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);

Ive also tried copying and pasting exactly what Sial wrote as well. The struggle is real right now.


#8

No you don't need the var. As you keep using the same variable that is declared on line 2 you don't need to redeclare it here again.


#9

The problem is what @sial mentioned that by using console.log = (myName) you've set console.log to now be myName. Which means now it is a string whereas before it was a function (some cool structure that is covered later). So what you need to do is first fix it and then and this seems to be stupid but is reallly important:

refresh the page and try again

because by refreshing the page you reset console.log to it's old value and now you should again be able to console.log something to the screen.


#10

I have: (and it worked)

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


#11
console.log("Milla");

here you should actually use the recently created myName variable instead.

console.log("myName");

And this just prints "myName" guess the idea was that you change the value of myName to be the substring(0,2) of your name and then print again:

 console.log(myName);

#12

Hm, but then it gives me

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


#13

Could you show your new code?


#14

Here..

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


#15

Hm as said the idea is that you use variables here instead of string literals ("anything written here" would be a string literal).
So this is ok:

var myName = "Milla";

Now you'd call

console.log(myName);

as you made sure by the previous statement that myName is now an alias for your name. Next you would change the value of myName by:

myName = myName.substring(0,2);

and last but not least you would print this new value of myName to see if it is working.

console.log(myName);

Same statement as before different output as you changed the value.


#16

thanks :slight_smile: yall for the help, muchos gracias :slight_smile:


#17

A post was split to a new topic: 26. It looks like you didn't log your whole name to the console


#18