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/116.0.5845.686 YaBrowser/23.9.5.686 Yowser/2.5 Safari/537.36

Challenge Information:

Basic JavaScript - Understand String Immutability

Why doesn’t my option work? Of course, I always knew that a Java script is impossible to understand how it works, but here you can’t understand the instructions, what exactly do they want to see from the students?

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

The only way to change myStr would be to assign it with a new value
wich you did in line two …

yes, but this is not implemented in the application

what hapens when you delete this?

Then it worked, but why is it not in the instructions to remove something?

it is seying in this word:
The only way to change myStr would be to assign it with a new value

Hello Masha,

The challenge in this one wants you to correct the assignment from using index based assignment like this:

myStr[0] = "J"

To this:

Mod edit: Removed Solution

You can see in the challenge, there’s a comment that says [Change this line]. You only need to change that single line and nothing else.

The challenge wants to make you get the point: You can’t change a single letter in a string after it has been created using the square brackets notation like [0], [1], [2] which you usually use when changing the value of an array or an object.

I think you misunderstand the challenge because it’s text-based instructions?

I hope that clear things up. Let me know if you have any more questions.

Cheers!
Nathan

Please do not provide code solutions to the challenges

1 Like

Why remove something if the instructions don’t indicate it?

myStr = "Hello World";
myStr[0] = "H"; // Change this line

You were supposed to change the second line, but instead you added the first line. The directions didnt say to delete that line because you were supposed to change it. Instead you added a new line which forced you to remove the line to pass

2 Likes

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