26.Change variable values.Sorry i need help again!


#1

// On line 2, declare a variable myName and give it your name.
console.log(var myName === "Sam")

// 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")

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

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


#2

Hi Brian,

Needing help is fine, it's what these forums are for :)

  • Line 2, you need to remove the console.log() bit, but leave the part between the parenthesis (())
  • Line 5, you can't have quotes around a variable, it'll be read as a string and print out myName instead of Sam
  • Line 9, use the code inside the parentheses on line 13, removing the quotes around myName again and set myName equal to that.
  • Line 13, just print out myName again like you do on line 5.

Line 9 should look roughly like this:

myName = myName.substring(0, 2);

Please let me know if you've got any more questions or are still having trouble with the exercise :)


#3

2 posts were split to a new topic: 26.Change variable values


#5

2 posts were split to a new topic: 26.Change variable values


#6

A post was split to a new topic: 26.Change variable values


#7

Can you break it down for me because i don't really get it.


#8

@microrockstar50701 I think I already did... which steps are you having trouble with?


#9

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

the output is only "Mo"

and >> "
Oops, try again. It looks like you didn't log your whole name to the console."
i can't see what is wrong!
I can't continue


#10

Okay so first off all you need to refresh your browser because you've overwritten what console.log does by using =

I'll give you a couple examples and see if you can finish it off from there, if not let me know :slight_smile:

var myName = "Monika";

console.log(myName)  

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

#11

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

output>>

Oops, try again. Your code doesn't look quite right. Check the Hint if you need help!
TypeError: console.log is not a function


#12

You haven't done this bit yet.

Do that and come back to me if it throws any more errors

If that still wont work, press ctrl and f5

then use this

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


#13

thx.
now it works! ......


#14