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 trial

JavaScript Express Basics Using Templates with Express Express’s Response.render Method

Javier Briones
seal-mask
.a{fill-rule:evenodd;}techdegree
Javier Briones
Front End Web Development Techdegree Student 29,674 Points

How to get Visual Studio Code to ignore whitespaces?

Hello,

Whenever I need to go to the next line (by pressing 'Enter' on the keyboard) on Visual Studio Code, I get a syntax error saying " ',' expected", and I get this because I'm pressing 'Enter' and going to the next line. Visual Studio Code gives me an error instead of ignoring the whitespace(s). This usually happens when I'm typing a String. Below is the example:

app.get('/card', function(req, res){ res.render('card', {prompt: "Who is buried in Grant's Tomb?", hint: "Think about whose tomb"}); });

I press 'Enter' after the 'whose' (in order to go to the next line) and what Visual Studio Code does is to highlight 'tomb"});' and tell me there's a syntax error.

Is there an extension I need to download or do I need to change the Settings in order for Visual Studio Code to ignore whitespaces? Thanks in advance!

2 Answers

Steven Parker
Steven Parker
231,248 Points

It's not valid to go to the next line while inputting a string literal, and it sounds like VSCode is just telling you that.

If you want to break up a long line for readability, use can use concatenation:

var text = "This line is so long that I want to have the source "
         + "on two lines.";
Javier Briones
seal-mask
.a{fill-rule:evenodd;}techdegree
Javier Briones
Front End Web Development Techdegree Student 29,674 Points

Hi Steven,

Thank you for answering my question. In the videos, the instructors go to next line without using concatenation and their code doesn't get any syntax errors and it seems to run just fine, and I'm very positive they are using Visual Code Studio. Unless they are using another version of Visual Studios, I don't know why it's not working for me. Loot at the Express’s Response.render Method video starting at 06:55 so you can see what I mean. Thanks again!

Steven Parker
Steven Parker
231,248 Points

If you look at the line numbers on the left side, you can see that code is still being entered on the same line (12). So no "enter" was typed, it's just the UI automatically wrapping around.

You can toggle word wrap in Visual Studio Code using alt+z (option+z for mac users)