freeCodeCamp / freeCodeCamp

freeCodeCamp.org's open-source codebase and curriculum. Learn to code for free.
https://contribute.freecodecamp.org
BSD 3-Clause "New" or "Revised" License
404.42k stars 37.86k forks source link

bug @ escape sequence or issue with instructions or both #13652

Closed hathcode closed 7 years ago

hathcode commented 7 years ago

Challenge Escape Sequences in Strings has an issue. User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36. Please describe how to reproduce this issue, and include links to screenshots if possible.

My code:


var myStr = "FirstLine\n\\SecondLine\\\r\nThirdLine"; // Change this line

The code I have written above satisfies the requested output, but does not display correctly and is judged incorrectly in the codechecker in the lesson. I have tested it on other platforms, and it ouputs exactly as requested. BTW, the instructions:

Here is the text with the escape sequences written out.

"FirstLinenewlinebackslashSecondLinebackslashcarriage-returnThirdLine"

are also misleading because that implies \n is not needed before the carriage-return and results in line three overwriting line two.

Why does my code work on a standard platform, but not here?

hathcode commented 7 years ago

var myStr = "FirstLine\n\SecondLine\\rThirdLine"; // Change this line

the above code passes (finally, pretty sure I had that at one point), but it DOES NOT produce ...

FirstLine \SecondLine\ ThirdLine

...which is the stated desired outcome. The result of the code that passes is ...

FirstLine \SecondLine\ThirdLine

or

Firstline Thirdlinene\

...where Thirdline overwrights the SecondLine as you would expect with \r but no \n.

raisedadead commented 7 years ago

Two issues with your code:

Please try once again, closing as not an issue with code base.

Thanks and happy coding!

hathcode commented 7 years ago

I had fixed that particular typo and got it passing as I mentioned. The rest of my post still follows and holds true. Did you read the rest of the post? Perhaps it is a browser issue? Even when I pulled up the devtools in Chrome and checked the console there, the output of the "passing" string is NOT what was requested in the challenge. Maybe it is works in some browsers (as I have read that different browsers treat \n and \r differently). That said, I tried it in my IDE and still had same outcomes. The codechecker is only checking that you have the string written a certain way, but it is apparently not checking the output. This issue needs to be reopened and addressed. Here's a SO post that discusses n vs r and highlights my points: http://stackoverflow.com/questions/10282314/what-is-a-r-and-why-would-one-use-it-with-a-n

raisedadead commented 7 years ago

My apologies, I missed on understanding the second comment on the thread.

raisedadead commented 7 years ago

The SO post surely helps. We have had this issue pop up quite a few times with issues such as the typos and unwanted chars.

What you explain sure is a case that needs to be handled.

Thanks for the report.

/cc @freeCodeCamp/moderators

raisedadead commented 7 years ago

@hathcode Just FYI, while we look at this once again. Different browsers have different implementations for the \r carriage return.

Chrome for instance chooses to ignore \r for a render on new line and while it renders \n on a new line.

systimotic commented 7 years ago

We recently made some changes to this challenge in the beta, as there were a lot of problems like this. First, we changed the sequence to something without \r\n, because as you noted, it acts weird. Then we changed the tests to test each part more specifically, hoping to reduce the amount of people confused by typo's they made.

You can check out the updated challenge on the beta site. @raisedadead @hathcode Could you please take a look at the new version, and see if it resolves this issue?

hathcode commented 7 years ago

Thanks @raisedadead for diving back into this. I did notice that there were quite a few issues related to this lesson. Perhaps a rewrite is in order? The issue did make me dive into the nuances of /r and /n, and I learned quite a bit! But I'm sure y'all don't want this to keep popping up either. Maybe just keeping it simple, clarify /r and /n a little more (maybe a link to the SO for more info), and it seems to me the convention of having /n with /r is more standard across browsers than /r alone for rendering a new line (Considering where they come from, it makes more sense to me that way, I actually learned to type on a typewriter), and changing the test requirements? My two cents worth (which maybe 1 cent ;-) ).

hathcode commented 7 years ago

@systimotic I think that's much better! Seems to accomplish the desired goal and is much more straightforward. May I still recommend a link to some clarification on /n vs /r? Reason being the first time I learned them elsewhere I really didn't understand them very well, and this issue made me think about it in a different way and dive deeper. They also seem to pop up in interview questions from time to time, though I can't say how often they are used by professional programmers since I'm still looking for my first programming job :-). Again, my pennysworth!

systimotic commented 7 years ago

@hathcode I get where you're coming from. I'd be open to adding a link if you could find a good resource.

One big advantage that the new version of the challenge has is that it no longer suggests that a carriage return creates a new line. We currently don't elaborate on the carriage return, backspace and form feed characters. I think that makes sense, as they are quite a bit more complicated to understand, and rarely used. A carriage return is sometimes used in combination with a linefeed, because Windows, but not in Javascript.

If there is a good resource that explains these in an easy to understand way, I think adding it would be fine. However, I think the Stack Overflow post might confuse and scare campers more than it helps them. In that case, I think leaving those characters unexplained is a better option. We could potentially even remove them from the table.

raisedadead commented 7 years ago

Maybe a forum wiki article (re-worded) one based on the SO post should be a way to go?

systimotic commented 7 years ago

@raisedadead That sounds like a great idea to me!

systimotic commented 7 years ago

@hathcode Would you be willing to create a forum article to explain these escape characters? Here are our guidelines for creating a wiki article https://forum.freecodecamp.com/t/guidelines-and-rules-for-wiki-articles/51920 If you don't yet have the trust level and aren't in for browsing around on the forum, but you would like to write the article, you can share the draft here and we'll make sure it ends up in the wiki.

ghost commented 7 years ago

i think the right one would be= "FirstLine\n\\Secondline\\rThirdLine";
but with this code i get 3 error messages back, but when i use the "carrage return" before the "backslach escape"= "FirstLine\n\\Secondline\r\\ThirdLine"; i get only one (myStr should have encoded text with the proper escape sequences and no spacing). Somebody help please...

(https://github.com/freeCodeCamp/freeCodeCamp/issues/13794)

hathcode commented 7 years ago

@systimotic Sorry so long in getting back on here. I'd be glad to create an article! I'll look at the wiki and either post on the forum or here with the draft as you mentioned. Might take me a bit, but I'll get it done as soon as possible.

systimotic commented 7 years ago

@hathcode Awesome, I'm looking forward to it! Don't worry, there's no hurry.

mohamedwahshey commented 7 years ago

Here it is::

removed solution by mod

You welcome.

QuincyLarson commented 7 years ago

@hathcode We're planning to create guide articles for all the challenges that don't already have one. Would you be interested in creating a guide article for this challenge and adding a brief explanation about /r vs /n in that article? You could model it after the other articles here: https://forum.freecodecamp.com/c/guides

Since this is fixed in beta, I'm going to go ahead and close the issue.