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 trialMarlene Guzman
9,231 Pointspoints is undefined
I keep getting undefined for the number of points. Can anyone look at my code because im not spotting the error. Thank you!
//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
const https = require("https");
function printMessage(username, badgeCount, points){
const message = `${username} has ${badgeCount} total badge(s) and ${points} points in JavaScript`;
console.log(message)
}
function getProfile(username){
// connect to the API URL (https://teamtreehouse.come/username.json
const request = https.get(`https://teamtreehouse.com/${username}.json`, response =>{
let body = '';
// Read the date in
response.on('data', data=>{
body += data.toString()
});
response.on('end', () =>{
//Parse the data
const profile = JSON.parse(body);
printMessage(username, profile.badges.length, profile.points.javaScript)
})
//Print the data
});
}
const users = ['chalkers', 'alenaholligan','davemcfarland'];
users.forEach(getProfile);
5 Answers
KRIS NIKOLAISEN
54,971 PointsMake it uppercase
Steven Parker
231,269 PointsTo make your project easily replicated by folks wishing to help, you can make a snapshot of your workspace and post the link to it here.
Also, when the question is about something in a course, providing a link to the course page is useful (this is done for you if you start a question using the page's "Get Help" button).
In the meantime, you might try using the console to see what's in the "body" in the "end" handler, and also what is in the "profile" after the body is parsed.
KRIS NIKOLAISEN
54,971 PointsThe J in JavaScript is uppercase here:
printMessage(username, profile.badges.length, profile.points.JavaScript)
Marlene Guzman
9,231 Pointsit shows lower case on my code.
Steven Parker
231,269 PointsSo did changing the case fix it?
Marlene Guzman
9,231 PointsMy code got deleted because the editor refreshed itself so I moved forward.
Steven Parker
231,269 PointsYou could always go back and copy the code above and paste it in.