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

APIs

benjaminmosery
benjaminmosery
6,346 Points

Syntax Error: Unexpected end of input

Whenever I try to run the code below, I get:
}); ^ "Syntax Error: Unexpected end of input"

This is my current code:

// Problem: We need a simple way to look at a user's badge count and JavaScript points
// Solution: Use Node.js to connect to Treehouse's API to get profile information to print out
//Require https module
const https = require(`https`); 
const username = "benjaminmosery";  //VARIABLE FOR USERNAME IN TREEHOUSE WEBSITE

// function to print message to console
function printMessage(username,badgeCount,points){
const message = `${username} has ${badgeCount} total badge(s) and ${points} points in Javascript.` ;
console.log(message);
}
//Connect to the API URL (https://teamtreehouse.com/username.json)
const request = https.get(`https://teamtreehouse.com/${username}.json`, response  => { 

//REQUEST TREEHOUSE WEBSITE     
//CALL RESPONSE IN DIRECTORY USING.DIR  
console.log(response.statusCode);               
//Read the Data in
let body = “”;
response.on('data', data => {   
            //GETTING THE BODY BY WRITING IN THE WEBSITE RESPONSE
    body += data.toString();)  //HAVING THE DATA ADDED TO THE BODY
  });               //TURNED INTO A STRING

response.on(`end`, () => {
//Parse the Json Data (as its in the string)
console.log(body)};   //END RESPONSE TO THE DATA AS THE BODY, LOGGING IT INTO THE CONSOLE
console.log(typeof body);   //DETECTS THE WHAT TYPE OF OBJECT IS THE DATA TAKEN FROM THE BODY
//Print the Data
});

What am I doing wrong? I know it is probably something simple, but the code looks like what is stated in the video.

Moderator edited: Markdown added so that code renders properly in the forums.

4 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi again, benjaminmosery! Yes, I do have some suggestions and I did manage to get it to work. Sorry, I was busy working it out when I got your message. There are a couple of things going on here. First, you meant to set body to an empty string, but check those quotation marks that you're using. They're the incorrect type of quotation marks.

You wrote:

let body = “”;

But that should be:

//note the straight up and down double quotes here
let body = "";

Secondly, you have a stray closed curly brace:

You wrote:

console.log(body)}; 

But that should be just:

// note the removal of the }
console.log(body); 

Finally, somehow you managed to delete the closed curly brace and closed parenthesis that should be at the bottom. Right now, you only have one set, but there should be two.

The last two lines of app.js should look like this:

    });
});

Let me know if this did the trick! :sparkles:

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! You have a stray closing parenthesis on one line which I believe might be causing your error.

You wrote:

 body += data.toString();) 

But that should be:

 body += data.toString();

Let me know if this helps or if you're still stuck! :sparkles:

benjaminmosery
benjaminmosery
6,346 Points

Jennifer, I erased the extra parenthesis (good catch, thank you!) but the error is still there. Here is my current code:

// Problem: We need a simple way to look at a user's badge count and JavaScript points // Solution: Use Node.js to connect to Treehouse's API to get profile information to print out //Require https module const https = require(https); const username = "benjaminmosery"; //VARIABLE FOR USERNAME IN TREEHOUSE WEBSITE

// function to print message to console function printMessage(username,badgeCount,points){ const message = ${username} has ${badgeCount} total badge(s) and ${points} points in Javascript. ; console.log(message); } //Connect to the API URL (https://teamtreehouse.com/username.json) const request = https.get(https://teamtreehouse.com/${username}.json, response => {

//REQUEST TREEHOUSE WEBSITE
//CALL RESPONSE IN DIRECTORY USING.DIR
console.log(response.statusCode);
//Read the Data in let body = ``; response.on('data', data => {
//GETTING THE BODY BY WRITING IN THE WEBSITE RESPONSE body += data.toString(); //HAVING THE DATA ADDED TO THE BODY }); //TURNED INTO A STRING

response.on(end, () => { //Parse the Json Data (as its in the string) console.log(body)}; //END RESPONSE TO THE DATA AS THE BODY, LOGGING IT INTO THE CONSOLE console.log(typeof body); //DETECTS THE WHAT TYPE OF OBJECT IS THE DATA TAKEN FROM THE BODY //Print the Data } );

P.s. I noticed you organized my code so that it appears in that black box. Thank you! How did you do that for future reference?

Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

benjaminmosery I posted a link to the Markdown basics course below your code. It's about an hour long and really fun! There's also a "Markdown Cheatsheet" linked at the bottom of the "Add an Answer" box, but really, do yourself a favor and take the Markdown Basics course when you have a spare hour. Not only is markdown used here, but also elsewhere. Most notably (while you're learning to code) it is used in GitHub. You can make some super snazzy README.md files for your projects with markdown :smiley:

benjaminmosery
benjaminmosery
6,346 Points

Will do! Before I start on that do you any other suggestions for my Syntax Error issue? I've tried reformatting every parenthesis and closed off function to no avail.

benjaminmosery
benjaminmosery
6,346 Points

Jennifer, Thanks again for the quick response. After implementing your suggestions I got the code to run. However, I used ``on the body variable:

let body =``;

Instead of the noted straight double quotes which I do not think I have on my keyboard. I assume that this is only a quick-fix and that I may need to use the straight double quotes at some later point in my coding. How do I get them?