Instructions are confusing

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/97.0.4692.71 Safari/537.36 Edg/97.0.1072.55

Challenge: Understand String Immutability

Link to the challenge:

Hello there.

Do you have a question?

If so, please edit your post to include it in the Tell us what’s happening section.

Learning to describe problems is hard, but it is an important part of learning how to code.

Also, the more information you give us, the more likely we are to be able to help.

my solution

let myStr = “Jello World” ;

myStr = “Hello World” ;
myStr [0] = “H” ;
but its not working

This is the thing that the instructions very specifically said wouldn’t work, so I’m not surprised that it doesn’t work.

Hi @techlife !

Welcome to the forum!

Strings are immutable.
That means you can’t alter one letter of a string.
This does not work

let myStr = "Bob";
myStr[0] = "J";`

So, if you want to change the value of the variable myStr then you need to assign a whole new string to it.

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

myStr used to be "Bob" but then we assigned a new value to it called "Job"

In your challenge you have a string of "Jello World".
But you can’t just change one letter of a string like this

myStr[0] = "H";

That violates the rules on how strings work in programming.

Instead you need to assign a whole new word of "Hello World" to the myStr variable.

A few more hints to help you solve the problem.

No.1:
You solution only needs to be one line.

No.2:
Look very carefully at this line of the example code

myStr = "Job";

Follow that structure, but use the correct string.

Hope that helps!

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