Challenge Escape Sequences in Strings has an issue.
User Agent is: Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; AskTbORJ/5.15.9.29495; BRI/2; GWX:QUALIFIED; rv:11.0) like Gecko
.
Please describe how to reproduce this issue, and include links to screenshots if possible.
My code:
var myStr = "FirstLinen\Secondline\rThirdLine"; // Change this line
var myStr = "FirstLine\n\\Secondline\\\rThirdLine"; // Change this line
This challenge keeps popping up every now and then, should we just over-haul this?
/cc @FreeCodeCamp/moderators
@raisedadead it works after resetting but that shouldn't be happening :cold_sweat:
If you guys take it down, new folks might not know anything about escape characters because that's the only challenge on escaping characters.
@M1L2 The reason your code didn't work was because your l
in Secondline
was lower case, while it should be upper case 馃檪 I wrote this a few hours ago, by now Dylan also said this in your duplicate issue https://github.com/FreeCodeCamp/FreeCodeCamp/issues/12411
@raisedadead There was an issue with the return carriage, but that has been changed (commit).
Looking through issues about this challenge, I can spot three different categories:
We can work on item 2 in this issue.
Edit: I am a master at pasting the wrong links. I fixed them now. 馃槄
Second edit: Changed the formatting so that is hopefully less confusing.
@systimotic thanks a ton for your deep and in-depth insights on this.
I think this could be improved by having tests that look at smaller sections of the variable. If they check for each escaped character individually, we can have more precise error messages.
This is particularly interesting and I guess would state clearly for going about this issue.
Yup, we can't do much about the Typos.
Thanks again for your suggestions, am tagging this as help wanted for the tests, and I agree we can handle the third problem with the separate issue that we already have for it.
@raisedadead My formatting was a bit messy, I think that may have confused you. I edited it to hopefully make more sense.
The third problem, the one that is handled in the other issue, is the problem that needs more tests.
@raisedadead @systimotic
Hi guys, I had a think about this - maybe it could be resolved by splitting the first test into two parts and then having a separate test for each special character which specifies where it should be placed:
1) myStr
should contain no spaces
2) myStr
should contain the strings FirstLine
, SecondLine
and ThirdLine
(remember it's case sensitive)
3) FirstLine
should be followed by the newline character n
4) SecondLine
should be preceded by the backslash character \\
5) SecondLine
should be followed by the backslash character \\
6) ThirdLine
should be preceded by the carriage return character r
I think the following code should do the job?
1) assert(myStr.match(/\s/g).length == 0, 'message:
...
2) assert((myStr.match(/FirstLine/g).length ==1 ) && (myStr.match(/SecondLine/g).length == 1) && (myStr.match(/ThirdLine/g).length == 1), 'message:
...
3) assert(myStr.match(/FirstLine\n/g).length == 1, 'message:
...
4) assert(myStr.match(/\\SecondLine/g).length == 1, 'message:
...
5) assert(myStr.match(/SecondLine\\/g).length == 1, 'message:
...
6) assert(myStr.match(/\rThirdLine/g).length == 1, 'message:
...
Could also have a test for the final correct answer to ensure that people aren't adding in extra characters between the phrases checked above but that seems unnecessary to me.
I'm new to contributing but would be keen to submit a pull request for this if you think it's correct?
@billy-reilly thanks for taking a dig at this. I guess, this is a very clear breakup of going at this issue, waiting for @systimotic's confirmation, and I guess we can go forth.
@billy-reilly that looks like a comprehensive set of tests!
@billy-reilly Thanks a lot for taking a look at this!
Your suggested changes look great!
Since the live version, this challenge has changed a bit. You can check out the updates here on the beta: https://beta.freecodecamp.com/en/challenges/basic-javascript/escape-sequences-in-strings
A pull request would be awesome!
A couple of notes on your tests:
The tab and newline character would both count as whitespace under the \s
test. In this case, testing for a space character () would probably be the best solution.
You may already be aware of this, but for the actual test files, every backslash will have to escaped itself.
The tests for this challenge are here. If you run into any problems, feel free to go to our contributors chatroom.
var myStr = "FirstLinentSecondLinenThirdLine"; // Change this
what about when it also says "myStr should contain a tab character t which follows a newline character"
Most helpful comment
@raisedadead @systimotic
Hi guys, I had a think about this - maybe it could be resolved by splitting the first test into two parts and then having a separate test for each special character which specifies where it should be placed:
1)
myStr
should contain no spaces2)
myStr
should contain the stringsFirstLine
,SecondLine
andThirdLine
(remember it's case sensitive)3)
FirstLine
should be followed by the newline charactern
4)
SecondLine
should be preceded by the backslash character\\
5)
SecondLine
should be followed by the backslash character\\
6)
ThirdLine
should be preceded by the carriage return characterr
I think the following code should do the job?
1)
assert(myStr.match(/\s/g).length == 0, 'message:
...2)
assert((myStr.match(/FirstLine/g).length ==1 ) && (myStr.match(/SecondLine/g).length == 1) && (myStr.match(/ThirdLine/g).length == 1), 'message:
...3)
assert(myStr.match(/FirstLine\n/g).length == 1, 'message:
...4)
assert(myStr.match(/\\SecondLine/g).length == 1, 'message:
...5)
assert(myStr.match(/SecondLine\\/g).length == 1, 'message:
...6)
assert(myStr.match(/\rThirdLine/g).length == 1, 'message:
...Could also have a test for the final correct answer to ensure that people aren't adding in extra characters between the phrases checked above but that seems unnecessary to me.
I'm new to contributing but would be keen to submit a pull request for this if you think it's correct?