Overriding a variables value

// Setup
var lastName = "Lovelace";
var thirdLetterOfLastName = "hello";
// Only change code below this line
var thirdLetterOfLastName = lastName[2]; // Change this line

why isn’t the value of thirdLetterOfLastName v but not hello, is this the process of overriding new values for variables?
thanks in advance:)

HI @Kasakapen !

You don’t need to redeclare the thirdLetterOfLastName .

You declared it here

so if you want to assign a new value to it then you can just reference the variable name.

 thirdLetterOfLastName = lastName[2];

Your last line of code is telling the computer to assign the letter v to the variable called thirdLetterOfLastName

The value of the thirdLetterOfLastName used to be "hello" but this line of code

 thirdLetterOfLastName = lastName[2];

tells the computer to assign it a new value which is the letter v.

1 Like