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 trialMoustafa Nassr
838 Pointscant figure out whats wrong
const https = require('https')
function printMessage(username, badgeCount, points) {
const message = `${username} has ${badgeCount} total badges and ${points} points in javaScript`;
console.log(message);
}
function getProfile(username) {
try {
const request = https.get(`https://teamtreehouse.com/${username}.json`, response => {
let body = "";
response.on('data', data => {
body += data.toString()
});
response.on("end", () => {
const profile = JSON.parse(body)
printMessage(username, profile.badges.length, profile.points.JavaScript)
})
});
} catch (error) {
console.error(error.message);
}
}
const users = process.argv.slice(2);
users.forEach(getProfile);
2 Answers
Tom Geraghty
24,174 PointsA few people have mentioned getting errors using the string literal `` and using the format username.json. One other forum question recommended formatting the request string literal like this:
const request = https.get(`https://teamtreehouse.com/${username}?format=json`, ...
Going in your browser, both username.json and username?format=json in the URL work and return the correct JSON object.
Changing your string literal to ?format=json may fix the issue but I'm not sure why. Anyone?
Alexander La Bianca
15,959 PointsCan you describe what issue you are having? But just from looking at the code it may seem that your url in https.get is not using proper quotes.
Henrik Christensen
Python Web Development Techdegree Student 38,322 PointsHenrik Christensen
Python Web Development Techdegree Student 38,322 Pointscant figure out whats wrong that does not really tell a lot about what the problem is - you might want to describe what problem you're experiencing + what error message you're getting? :-)