Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialAnthony Linares
3,060 PointsMy code is not working for the multi line example on the video
This is what I got. Keep in mind after the \ there is a new line.
const multiline = "Hello, students. \
Welcome to javaScript Basics. \
I hope you learn a lot!";
console.log(multiline);
7 Answers
Anthony Linares
3,060 Pointsyea. Is not working I don't understand what I am doing wrong. I rewrote the code and it said uncaught syntaxerror: Invalid or unexpected token. Is there a way I can upload a screenshot to the post?
Steven Parker
231,236 PointsWhen posting code, use Markdown formatting to preserve the code's appearance and retain special symbols.
If I understand correctly what you meant to show, here's your example using markdown:
const multiline = "Hello, students. \
Welcome to javaScript Basics. \
I hope you learn a lot!";
console.log(multiline);
That should work, but be aware that the output will appear on a single line (as shown in the video). The escapes allow you to continue the string on the next line, but they don't encode a newline in the string.
Steven Parker
231,236 PointsOn seeing the snapshot, it is clear that the cause of the "Invalid or unexpected token" error is that on line 14 (the one that says Welcome to javaScript Basics. \
), there are two spaces after the backslash. For the backslash to work as a line continuation escape, there must not by any characters between it and the newline.
Remove those spaces and the error will go away.
Anthony Linares
3,060 PointsThank you very much for the help Steven. I am just going to move on, hopefully once I get more experience with JS I hope to make less errors.
Steven Parker
231,236 PointsOK, but if you share that workspace snapshot we can identify the exact cause of the problem.
Anthony Linares
3,060 PointsHello Mr. Steve, here is the link https://w.trhou.se/vnu25iikgr. the file name is strings.js under js folder. Thank you.
Anthony Linares
3,060 Pointswow. Thank you very much Mr. Steve the code works now. I spend a decent amount of time on this problem and could not figure it out. Now I have a much better understand about the js syntax. Thanks again.
Anna Oleszczuk
6,010 Pointsthis worked for me:
const multiline = "hello, students. \n\ Welcome to JavaScript Basics. \ I hope you learn a lot!";
melanieelanduenas
Full Stack JavaScript Techdegree Student 528 Pointsthe video shows the multiline section works with the const html section on top but it doesnt. after trying out the H1 text, cut that section out and the multiline section will appear on console.
Steven Parker
231,236 PointsSteven Parker
231,236 PointsYou can cut and paste but be sure to use Markdown formatting (like I did above) to preserve the code's integrity. And you can also share an entire project if you use the snapshot function in the workspace and provide the link to that.
Anthony Linares — Glad to help. But normally, "best answer" would be selected on the one that contained the info that helped resolve your issue!
(you can change that now)