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 trialFareez Ahmed
12,728 Pointschalkers has 162 total badge(s) and undefined points in Javascript
Why are my points undefined?
var http = require("http");
var username = "chalkers";
function printMessage(username, badgeCount, points){
var 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)
//use http.get
var request = http.get('http://teamtreehouse.com/' +username+ '.json', function(response){
//console.dir(response);
//console.log(response.statusCode);
var body = "";
//Read data
response.on('data', function(chunk){
body += chunk;
});
response.on('end', function(){
var profile = JSON.parse(body);
printMessage(username, profile.badges.length, profile.points.Javascript)
});
//parse data
//print data
});
request.on("error", function(error){
console.error(error.message);
})
Matthew Levstek
962 Points"profile.points.JavaScript" not "profile.points.Javascript"
1 Answer
Parker Busswood
20,207 PointsWhen you handle the end of the response in response.on('end'), make sure you have JavaScript properly capitalized:
response.on('end', function(){
var profile = JSON.parse(body);
printMessage(username, profile.badges.length, profile.points.JavaScript)
});
Alejandro Londono
4,659 PointsAlejandro Londono
4,659 PointsI had the same problem,
If you look at your printMessage() function, you have called the JavaScript function wrong. s should be capitalized.