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 trialJonathan Ambriz
Courses Plus Student 3,902 PointsIt shows the same information regardless of the name..
This is the output I get from the console:
alenaholligan has 90 total badge(s) and 41 points in JavaScript
chalkers has 90 total badge(s) and 41 points in JavaScript
This is my code: // Problem: We need a simple way to look at a user's badge count and JavaScript points //Require https module const https = require('https');
//Function to print message to console
function printMessage(username, badgeCount, points){
const message = ${username} has ${badgeCount} total badge(s) and ${points} points in JavaScript
;
console.log(message);
}
// Solution: Use Node.js to connect to Treehouse's API to get profile information to print out
function getProfile( username ) {
//Connect to the API URL (https://teamtreehouse.com/username.json)
const request = https.get(https://teamtreehouse.com/username.json
, res => {
let body = '';
//Read the data
res.on('data', data => {
body += data.toString();
});
res.on('end', () => { //Parse the data const profile = JSON.parse(body); printMessage(username, profile.badges.length, profile.points.JavaScript); //Print the data }); }); }
getProfile("chalkers"); getProfile('alenaholligan');
1 Answer
Martin Sole
82,199 PointsHi
It doesn't appear that you are passing in the username parameter to the api call, the call you are making is accessing a dummy treehouse profile called username (https://teamtreehouse.com/username.json). You would need to use a template literal like https://teamtreehouse.com/${username}.json
to get the results for Andrew and Alena.