Tell us what’s happening:
I don’t understand why it keeps saying
TypeError:
Attempting to assign to randomly property Your code so far
// Setup
let myStr = "Jello World";
// Only change code below this line
myStr = "Hello World"; myStr[0] = "H"; // Change this line
// Only change code above this line
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.4 Safari/605.1.15
I think I understand now. The [0] = ‘H’ is supposed to be the outcome of code after I modify it and the challenge didn’t asked me to put that as part of the code. All I need to do is assign the correct value to the variable to make sure the first letter is H right?
Just to reiterate, in JS you cannot change individual letters of strings like that. In some languages you can, but not in JS. In JS, you either have to give it a complete, new string … or you need to build the new version of the string out of pieces of the old string, creating a new string. But the point is that it is “immutable”, you cannot “mutate” it. Once it is saved in memory, you cannot change it, only replace it.
This is actually true of all primitive types, but it’s mainly an issue with strings. Later on, there will be times when it is best to treat reference types like this, too, like with arrays and objects.