I have questions about about declaration choices here as well as the intended solution.
link to the skill test in question: Test your skills: Strings - Learn web development | MDN
The prompt:
We want you to change the value of [myString] as follows:
definition
const myString = 'Using *, we can work out that that if the two shortest sides of a right-angled triangle have lengths of * and *, the length of the hypotenuse is *.';
and later:
// Don't edit the code below here!
para1.textContent = myString;
- As far as I understand, strings are immutable — so it seems that the prompt of “changing the values of the string” doesn’t make sense from the start. The solutions that made sense to me were either changing the declaration of
myString
to uselet
or change the declaration usingconst
to some other name (e.g.startingString
) and then createdmyString
from that (e.g.let myString = startingString;
) - My first solution was to iteratively go through and use the
.replace()
method on the string but that feels error prone/clunky. I looked through the documentation for.replace()
and it feels like using a regex might make sense, but that feels like a quite different solution (https://codepen.io/isherifwilson/pen/xxXoZmP)