Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript Node.js Basics 2017 Building a Command Line Application Capturing Command Line Arguments

It 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
Martin Sole
80,284 Points

Hi

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.