26 Change variable values


#1


This is the message is displays "It looks like you didn't log the first 2 letters of your name to the console!"


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


#2

this bit of code:

// On line 7, change the value of myName to be just the first 2 
// letters of your name.
myName = "Sauls"

you should use substring to set myName to the first two letters of myName.


#3

I did do it but it still gives the same error


#4

please post an updated version of your code


#5

var myName = "Dwayne";
// 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.substring(0,2)
// On line 9, use console.log to print out the myName variable.
console.log(myName);


#6

You were asked to change the value of variable myName to the first two letters of your name.

To do so, you need to assign new value:

myName = myName.substring(0, 2);

#7

It passes through like this below, but I am still uncertain that it does not look right

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

~~~~


#8

updated it

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


#9

remove this line:

var myName = "Dw"

we are using substring, what you do here is just cheating. now, this line:

console.log(myName.substring(0.3))

0.3? That is a decimal number, this are function arguments, they are separated by comma's:

console.log(myName.substring(0,3))

counting starts from 0, so you currently log the letters at index 0,1 and 2 to the console. That is one to many


#10

I got stuck on this same question and maybe I did it wrong, but my updated code is below. It was accepted and shows I did it correctly. From what I can see, your quotes are off in the first var string; you don't need to find a length for line 4; On line 7 you don't need a substring, just literally change the value for the var from "Dwayne" to "Dw".

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


#11

Sure, you don't "need" to use substring, but you just learned it so you might as well practice it. Your program is going to be a lot more flexible for your many users if you don't have to hardcode in everyone's name and also the first two letters of their name.


#12

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


#13

You also need to print your old name and new name using console.log on the right lines


#14

So....maybe I am overthinking things here but I have read several of the posts where people are having trouble with this. I just came here to make sure I was doing things right, although I guess it doesn't matter since it did say I got it right on the first try (I guess I was just surprised how easily I got it; Not trying to brag).

Anyway, is it wrong to just assign a new variable to the short name? This is my code:

var myName = "Patrick";
console.log(myName);
var myShortName = myName.substring(0,2);
console.log(myShortName);

I'm asking because I didn't see anyone trying this or suggesting this.


#15

your code is fine, there are multiply ways to solve a problem, we can't cover them all. That you haven't seen your solution doesn't mean it is wrong


#16

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