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 trialMike Hatch
14,940 PointsWhy do Double Quotes Vs. Single Quotes matter here?
For the most part, with the exception of end user sentence strings, I code in single quotes. The following code is working code. But as soon as you change the double quotes to single quotes (I'm not sure exactly where) it will break the app. This is very strict code. For instance, there are single quotes used in some places, but not in others. Up until this point I haven't had any issues with coding single vs. double. Why is it so strict in this app?
router.js
//Handle HTTP route GET / and POST / i.e. Home
function home(request, response) {
//if url == "/" && GET
if (request.url === "/") {
//show search
response.writeHead(200, { 'Content-Type': 'text/plain' });
response.write("Header\n");
response.write("Search\n");
response.end('Footer\n');
}
//if url == "/" && POST
//redirect to /:username
}
//Handle HTTP route GET /:username i.e. /chalkers
function user(request, response) {
//if url == "/...."
var username = request.url.replace("/", "");
if (username.length > 0) {
response.writeHead(200, { 'Content-Type': 'text/plain' });
response.write("Header\n");
response.write(username + "\n");
response.end('Footer\n');
//get json from Treehouse
//on "end"
//show profile
//on "error"
//show error
}
}
module.exports.home = home;
module.exports.user = user;
2 Answers
Jennifer Nordell
Treehouse TeacherHi there, Mike Hatch ! Unfortunately, I think you may have fallen victim to the typo monster. Not to worry, he gets me too on occasion. I was interested in why this was so strict so I took your challenge and replaced all double quotes with single quotes. I cannot get the app to break.
You can take a look at my workspace snapshot.
As far as I can tell, everything seems to work as it intended at least up until this point.
Hope this helps!
Ryan Emslie
Full Stack JavaScript Techdegree Student 14,453 PointsI ran into a similar situation. I had double quotes around "Content-Type": "text/plain" . When I changed my code to single quotes 'Content-Type': 'text/plain' my code worked. I will add that I am not coding within the Treehouse workspaces. I am using Visual Studio Code.
Mike Hatch
14,940 PointsMike Hatch
14,940 PointsThanks for taking the time to check on this, Jennifer! Now I'll never know what the bug was because I continued on, saved the files and closed out since you answered. When I debugged it I thought it was the quotes that fixed it, but it had to be something else. Lesson Learned: Poor debugging tactics I guess.