Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Challenge [Search and Replace]: Cannot assign to read only property '0' of string 'leaped' #11834

Closed
vasadhananjay opened this issue Nov 27, 2016 · 3 comments

Comments

@vasadhananjay
Copy link

vasadhananjay commented Nov 27, 2016

Challenge Search and Replace has an issue.
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36.

Running the code below results in the following issue. I've validated that this function executes fine.

TypeError: Cannot assign to read only property '0' of string 'leaped'

JSBin: http://jsbin.com/tegiwaseti/edit?html,js,output

My code:

function myReplace(str, before, after) {
  // Capitalized
  if (before.charCodeAt(0) < 97) {
    after[0] = after[0].toUpperCase();
  }
  else {
    after[0] = after[0].toLowerCase();
  }
  str = str.replace(before,after);
  return str;
}

myReplace("A quick brown fox jumped over the lazy dog", "jumped", "leaped");
@systimotic
Copy link
Member

Hi @vasadhananjay! Thank you for reporting this issue.

You can not edit a string with that syntax (although it would be cool if you could). This challenge explains it https://www.freecodecamp.com/challenges/understand-string-immutability

This is a standard message notifying you that this issue seems to be a request for help. Instead of asking for help here, please click the "help" button on the challenge on Free Code Camp, which will take you to the help chatroom for that specific challenge. You can also view our full list of official chatrooms.

If you think I'm wrong in closing this issue, please reopen it and add further clarification.
Happy coding!

@vasadhananjay
Copy link
Author

Agreed that it shouldn't work. But it shouldn't throw an error either should it?

@systimotic
Copy link
Member

@vasadhananjay That's how Javascript works, we can't really influence it.
I like that it throws an error. If it doesn't work, but it doesn't throw an error, it would take me way longer to figure out what went wrong.
I'm genuinely curious, what do you think it should do?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants