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

Escape Sequences in Strings lesson has a bug. #12091

Closed
BBLThumper opened this issue Dec 17, 2016 · 7 comments
Closed

Escape Sequences in Strings lesson has a bug. #12091

BBLThumper opened this issue Dec 17, 2016 · 7 comments

Comments

@BBLThumper
Copy link

Issue Description

I think the "Escape Sequences in Strings" lesson has a bug.

I am going through the Javascript course on FreeCodeCamp.com and am stuck at this challenge, 'Escape Sequences in Strings':

Assign the following three lines of text into the single variable myStr using escape sequences.

FirstLine
\SecondLine\
ThirdLine

You will need to use escape sequences to insert special characters correctly. You will also need to follow the spacing as it looks above, with no spaces between escape sequences or words.

Here is the text with the escape sequences written out.

"FirstLine newline backslash SecondLine backslash carriage-return ThirdLine"

Here is how I'm writing the code example:

js var myStr = "Firstline\n\\Secondline\\\rThirdline";

In the lesson, the check requires there to be only one \n. The \r doesn't seem to function properly. I have tried different work arounds and searching hasn't provided any direction. I have tried using 'console' in the developer window of the browser and it appears \n is working but the \r is not.

According to the rules of the instruction,

js var myStr = "Fristline\n\\Secondline\\\r\nThirdline";

is not valid by the lesson standards.

Is the carriage-return not working?
Am I misunderstanding the lesson?

According to the book 'Javascript Bible' by Danny Goodman, chapter 15 'The String Objects', section 'Special Inline Characters' states:

"In most cases, browsers ignore carriage returns or render them like spaces."

https://books.google.com/books?id=WMr2NEG88icC&pg=PT262&lpg=PT262&dq=javascript+carriage+return&source=bl&ots=dWFLqN0rlO&sig=eZGo_74AHZq_4e2pxmtiqXz6l9s&hl=en&sa=X&ved=0ahUKEwivlMaEqu_QAhWBOSYKHSviBM44HhDoAQgjMAI#v=onepage&q=javascript%20carriage%20return&f=false

To highlight this issue I put similar isolating code found in the lesson inside console.log(); in the Developer window of the browser. I received some interesting results.

This is what occurs in the browser as displayed in console:

js console.log("escape characters use a \\\nbackslash. But a carrige-return \rdoes this!");

escape characters use a \
backslash. But a carrige-return does this!

This is the same code copied to clipboard from the browsers console display and pasted into an editor:

js console.log("escape characters use a \\\nbackslash. But a carrige-return \rdoes this!");
escape characters use a \
backslash. But a carrige-return
does this!

Browser display:

js var myStr = "Firstline\n\\Secondline\\\rThirdline"; console.log(myStr);
Firstline
\Secondline\Thirdline

Clipboard paste result:

js var myStr = "Firstline\n\\Secondline\\\rThirdline"; console.log(myStr);
Firstline
\Secondline\
Thirdline

Browser Information

Firefox Version 49.0.2
Build ID 20161019084923
Update Channel release
User Agent Mozilla/5.0 (Windows NT 6.2; Win64; x64; rv:49.0) Gecko/20100101 Firefox/49.0
OS Windows_NT 6.2

  • Browser Name, Version: Firefox 49
  • Operating System: Windows 8
@BBLThumper
Copy link
Author

BBLThumper commented Dec 18, 2016

I don't know how familiar you are with the website this github account issue tracker was made for.

  1. It is an interactive tutorial website to teach programming of various types. The 'js' prefixed to the code identifies it as Javascript, and is laid out in the template for reporting bugs/quirks/issues. The websites interactive tutorials teach many different language constructs and so the identifier gives those researching the issue a heads up of which language they will be dealing with. I followed the templates patterns in posting this issue.

  2. Strings have no requirement to be capitalized for the proper operation of the program. I have copied and pasted here, that style copied directly into this issue from the actual lesson.

They are two word sentences, in sentences only the first word is capitalized:
First line. Second line. Third line.

If you have any suggestions for resolving the issue outlined in my original post then please respond to the issue described. If you need further clarifications I would be more than happy to provide any details necessary to help resolve this issue.

@raisedadead raisedadead added the status: discussing Under discussion threads. Closed as stale after 60 days of inactivity. label Dec 18, 2016
@raisedadead
Copy link
Member

@BBLThumper thanks a lot for reporting!

Let's keep focus and keep the discussion to the issue that you are facing,(we can discuss aesthetics in chat rooms, they are not related to FCC codebase, and hence not the issue tracker):

According to the rules of the instruction,

var myStr = "FristLine\n\\SecondLine\\\r\nThirdLine";

is not valid by the lesson standards.

Is the carriage-return not working?
Am I misunderstanding the lesson?

While I can't seem to classify this as a bug yet, I agree with you that different browsers will behave differently with same escape characters, that's because how each individual browser implement themselves.

The aim of the challenge is to teach campers how escape sequences should be used in strings.

Let's discuss and keep this open for more comments and if we need to modify the challenge.

@spieg
Copy link

spieg commented Dec 18, 2016

I can believe \r behaves a bit strange in different ways of outputing. Maybe it'll behave different in UNIX or older macs. Maybe \n behaves strange in windows, cause windows should be \r\n.
So if there should be a \r in a challenge with so little explanation is imnsho a valid question.
That doesn't take away from the specs that are asking FirstLine SecondLine ThirdLine; and the automatic testing will fail on Firstline Secondline and Thirdline, let alone Fristline, and rightly so.

@raisedadead
Copy link
Member

So if there should be a \r in a challenge with so little explanation is imnsho a valid question.

I agree.

Anyone up for any suggestions on rewording or adding some better explanation, that does not complicate the challenge?

@raisedadead raisedadead added the help wanted Open for all. You do not need permission to work on these. label Dec 18, 2016
@systimotic
Copy link
Member

This looks like a duplicate of #10485
If I understood this issue wrong, please reopen it!

@systimotic systimotic removed status: discussing Under discussion threads. Closed as stale after 60 days of inactivity. help wanted Open for all. You do not need permission to work on these. labels Jan 7, 2017
@medha279
Copy link

They are saying to use newline character, why are you using carriage character? Everything is correct except the case sensitivity part. "FirstLine\n\t\SecondLine\nThirdLine". For this, I got accepted.

@spieg
Copy link

spieg commented Aug 24, 2018

Hi medhatrinky,

Since the start of this discussion, the lesson has changed. The Original lesson is included in the first post. The carriage return character has been removed from the newest version of the lesson.

@freeCodeCamp freeCodeCamp locked as off-topic and limited conversation to collaborators Aug 27, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants