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 trialterrenceg
Courses Plus Student 3,380 PointsGet an undefined value returned.
I get an undefined error when I run the code below in the node.js workspace. Please assist.
// 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 var https = require("https");
const username = "chalkers";
//Function to print messsage to console
function printMessage(username, badgeCount, points){
const message = ${username} has ${badgeCount} total badges(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 => {
console.log(response.statuscode);
//Read the data //Parse the data //Print the data
});
1 Answer
Joe Beltramo
Courses Plus Student 22,191 PointsThe methods in node,js follow a camelCase format. Try:
console.log(response.statusCode); // Capital C
Bruno Navarrete
Full Stack JavaScript Techdegree Graduate 22,246 PointsBruno Navarrete
Full Stack JavaScript Techdegree Graduate 22,246 PointsThis is probably it. I ran into that (annoying) wall several times too.
terrenceg
Courses Plus Student 3,380 Pointsterrenceg
Courses Plus Student 3,380 PointsThat worked perfect. Thank you!