JavaScript Node.js Basics Handling Errors in Node Handling Errors in Node

Johannes Scribante
Johannes Scribante
19,175 Points

Code challenge error is not helping me to find my error

Code Challenge: Create a variable request that stores the result of the get method. Error message: Bummer! You didn't declare the var, const or let variable.

I have tried many variations, but I get the same error and cannot figure out why I get this error. As the piece of code I write is: let request = ""; or respone.on('data', data => { let request = data.toString(); }); and some other variations in between.

Am I understanding the code challenge incorrectly? or is there something wrong with my code?

app.js
const https = require("https");

https.get("https://teamtreehouse.com/chalkers.json", response => {
  console.log(response.statusCode);
  let request = response.result;
});

2 Answers

Alexandra Barnett
Alexandra Barnett
Front End Web Development Techdegree Graduate 46,472 Points

Hi Johannes! The challenge wants you to assign the whole get request to the variable request (like below). I think it's a case of it being simpler than you or I might expect :)

const https = require("https");

const request = https.get("https://teamtreehouse.com/chalkers.json", response => {
  console.log(response.statusCode);
});

Hope that helps! :)

Johannes Scribante
Johannes Scribante
19,175 Points

Thanks Alexandra, your answer worked 100s! sometimes you just overthink these challenges!