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

shirshah sahel
shirshah sahel
10,035 Points

Stuck here, when I type Node app.js it would'nt show me the total number of badges and points in javascript .

https://w.trhou.se/6dun89f45p attach is the link to my workspace . I am wondering why it is not showing the total of badges and points in javascript for co workers. Thanks,

//Require https module
const https= require('https');
//Function to print message to console
 function printMessage(username, badgeCount, points){
 const message=`${username} has ${badgeCount} badges and ${points} points in javascript`;

   console.log(message);
 }
function getProfile(username){

// Connect to the API URL (https://teamtreehouse.com/username.json)

const request= https.get(`https://teamtreehouse.com/${username}.json`, response =>{          
              let body="";
             // Read the data
    response.on('data',data=>{
    body += data.toString();
    });
  response.on('end', ()=>{
            // Parse the data
            const profile= JSON.parse(body);
            printMessage(username, profile.badges.lenght, profile.points.javascript);

                // Print the data  
        });
       });
}

getProfile("chalkers");
getProfile("alenahollingan");

3 Answers

Steven Parker
Steven Parker
218,813 Points

On this line:

            printMessage(username, profile.badges.lenght, profile.points.javascript);

You have "lenght" instead of "length" and "javascript" instead of "JavaScript" (identifiers are case-sensitive).

And on this line:

getProfile("alenahollingan");

That should be "alenaholligan" (just two "n"s).

Also, depending on what version of Node.js you're using, you might not be able to use "let" unless you're also using "strict" mode.

shirshah sahel
shirshah sahel
10,035 Points

Awesome Steven, it totally worked . I need to practice how to type length.

And to add on Steven's point

'javascript' should have capital letters like so:

printMessage(username, profile.badges.lenght, profile.points.JavaScript);