Need more test for Escape Sequences in Strings.
See original GitHub issueChallenge 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 = “FirstLine\n\Secondline\\rThirdLine”; // Change this line
var myStr = "FirstLine\n\\Secondline\\\rThirdLine"; // Change this line
Issue Analytics
- State:
- Created 7 years ago
- Comments:12 (8 by maintainers)
Top Results From Across the Web
Escape Sequences in Strings - Free Code Camp - YouTube
This is a basic JavaScript tutorial on how to escape sequences in strings. In this tutorial series, we go over the curriculum that...
Read more >Escape Sequences in Strings, freeCodeCamp Basic Javascript
In this lesson we go over other escape sequences that we have access to such as newline, tab, and backspace (plus others).
Read more >Escape Sequences in C - GeeksforGeeks
List of Escape Sequences. Some coding examples of escape characters ... Check if two same sub-sequences exist in a string or not.
Read more >Process escape sequences in a string in Python
Most answers to this question have serious problems. There seems to be no standard way to honor escape sequences in Python without breaking...
Read more >Escape Sequences in Strings SecondLine\\ - JavaScript
Here your code fails of course, becasue once browser reaches \S it finds it faulty, simple becasue there is no \S! Challenge needs...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

@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:
myStrshould contain no spacesmyStrshould contain the stringsFirstLine,SecondLineandThirdLine(remember it’s case sensitive)FirstLineshould be followed by the newline character\nSecondLineshould be preceded by the backslash character\\SecondLineshould be followed by the backslash character\\ThirdLineshould be preceded by the carriage return character\rI think the following code should do the job?
assert(myStr.match(/\s/g).length == 0, 'message:…assert((myStr.match(/FirstLine/g).length ==1 ) && (myStr.match(/SecondLine/g).length == 1) && (myStr.match(/ThirdLine/g).length == 1), 'message:…assert(myStr.match(/FirstLine\n/g).length == 1, 'message:…assert(myStr.match(/\\SecondLine/g).length == 1, 'message:…assert(myStr.match(/SecondLine\\/g).length == 1, 'message:…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 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
\stest. 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.