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

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