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 trial

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

sam poplack
sam poplack
9,467 Points

How do I fix this error on my code to make it run properly

I Have been Working on this along with the lecture

const https = require('https');


function ptintMessage(username, badgecount, point) {
  const message = `${username} has ${badgecount} total badge(s) and ${point} points in Jscript`;
  console.log(message);
}
function getProfile(username) {
//connect to api url (https://teamtreehouse.com/username.json)

conts request = https.get(`https://teamtreehouse.com/${username}.json`, response => {
    let body = "";
    console.log(response.statusCode);
    response.on('data', data => {
               body + data.toString();
                });

                response.on('end', () => {
                            const profile = JSON.parse(body);
                            console.dir(profile);
                           printMessage(username, profile.badges.length, profile.points.JavaScript);
                            });
               });
}

In the Comand line it says that an error was thrown on the request variable here: conts request = https.get(https://teamtreehouse.com/${username}.json, response => {

Can someone show me what went wrong by chance?

2 Answers

Nikola Jankovic
Nikola Jankovic
10,793 Points

Misspelled conts request= > const request

Nikola Jankovic
Nikola Jankovic
10,793 Points

body + data.toString(); => body += data.toString();

Nikola Jankovic
Nikola Jankovic
10,793 Points

function ptintMessage => function printMessage