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

shirshah sahel
shirshah sahel
10,034 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
170,320 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,034 Points

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

Amanda Sharp
Amanda Sharp
14,928 Points

And to add on Steven's point

'javascript' should have capital letters like so:

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