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 trialA A
Full Stack JavaScript Techdegree Student 19,812 PointsSyntaxError: Unexpected token N
I'm getting an unexpected syntax error and I'm not sure why. When I execute the file in node.js with the const username, it retrieves the data, but when I comment the username out and add usernames with "" as a argument, it's giving me an error.
Any suggestions?
const https = require('https'); const username = "nickolasteixeira"; //This would be a static program, because we are tied to our username variable, just 1 variable
// Function to print message to console
function printMessage(username, badgeCount, points) {
const message = ${username} has ${badgeCount} total badges(s) and ${points} points in Javascript
;
console.log(message);
}
function getProfile(username) {
// Connect to the API URL (https://teamtreehouse.com/username.json)
var request = https.get(https://teamtreehouse.com/${username}.json
, response => {
var body = "";
//Printing out the status code to see if the url was able to connect
// console.dir(response.statusCode);
// Read the data
response.on('data', (data) => {
body += data.toString();
// process.stdout.write(data);
});
response.on("end", () => {
// Parse the data
// to figure out the type of object
// console.log(typeof body);
const profile = JSON.parse(body);
// Print the data
// console.dir(profile); OR
printMessage(username, profile.badges.length, profile.points.JavaScript);
});
//String to a data structure is called parsing.
}); }
getProfile(username); // getProfile("nickolasteixiera"); // getProfile("chalkers");
Steven Parker
231,059 PointsI'm a bit confused about when you "comment the username out" .. how would the username variable get set then?
A A
Full Stack JavaScript Techdegree Student 19,812 PointsA A
Full Stack JavaScript Techdegree Student 19,812 PointsSorry, I meant if you put any username in the parenthesis. For example -> "nickolasteixeira"