Basic JavaScript - Understand String Immutability

Tell us what’s happening:
Describe your issue in detail here.

Your code so far

// Setup
let myStr = "Jello World";

// Only change code below this line
myStr[0] = "H"; // Change this line
// Only change code above this line

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36 Edg/114.0.1823.67

Challenge: Basic JavaScript - Understand String Immutability

Link to the challenge:

You didn’t make any changes to the original code. Help us understand what you don’t understand by asking a specific question.

sir in myStr first word is 0. In index[0].
then next line of code it changes the value of j. Then what is the issue I can’t understand

In the code you posted above, myStr is set to the string “Jello World” and thus index[0] would be “J”.

The next line is:

myStr[0] = "H";

This attempts to change the first letter in myStr from “J” to “H” but it is invalid syntax and can’t be done that way. You need to make that change by changing the entire string at once.

how to solve it. sir…

Look at how the example in the instructions was solved. They replaced the entire string with a new string.

let myStr = "Bob";
myStr = "Job";

You can use this same concept to solve it.

// Setup
let myStr = “Jello World”;

// Only change code below this line
myStr = “H”; // Change this line
// Only change code above this line

not running sir

You changed myStr to the string “H”. The instructions are asking you to change it to the string “Hello World”.

Also, please use the triple back tick method to paste your code in here. On a line by itself type three back ticks. Then on the first line below the three back ticks paste in your code. Then below your code on a new line type three more back ticks. The back tick on my keyboard is in the upper left just above the Tab key and below the Esc key. You may also be able to use Ctrl+e to automatically give you the triple back ticks while you are typing in the this editor and the cursor is on a line by itself. Alternatively, with the cursor on a line by itself, you can use the </> button above the editor to add the triple back ticks.

1 Like

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