I allso need help with the quotes generator

I recieved a token from a quotes web site but something is wrong:
Here is the pen’s url:

https://codepen.io/captain_hadock/pen/jZdJag

-open the console and check for error
Uncaught ReferenceError: htmlString is not defined

function renderHTML(data) {
  var htmlString = "";
  htmlString += "<p>" + data + ".</p>"
}
console.log("STATUS" + htmlString);

you were trying to access a variable which was defined inside a local scope

1 Like

Thank you. I changed the code but it still doesn’t work.
What I realy want to know is how do I debug it. Why is it that the command console.log (‘somedata’ );
doesn’t yield any result that will help me keep track on my code

It would help to know exactly which line you’re talking about, but I’m seeing more than one error in your code that would stop your logs from working.

The first thing you need to do is clean up your code. Code that isn’t well formatted becomes hard to read, and then you make mistakes like on line 25, where you’re calling ourRequest.send() inside of your onload event. You can fix most of your issues just by using the autoformatter in CodePen. Click the arrow on the upper right.

29%20PM

Once your code is readable, you’ll want to check the documentation on using XHR objects to make sure you’re implementing it correctly.

There is one major issue in your case and the console error tells you exactly what it is. Once you’ve fixed that, you’re going to come across another 3-4 bugs. Thankfully, you don’t actually have to use XHR because it’s a bug prone, crappy API. You can now use fetch natively and it works much better for most AJAX use cases.

Generally, keep an eye on your dev console. You’re not allowed to ignore anything red or yellow. If it’s red, it’s an error and very likely caused by your code or a browser plugin. If it’s yellow, it’s a warning and it could be caused by your code, Codepen, or a browser plugin. You need to understand what it’s saying, but you might not be able to fix it. Once your code is free of error messages and you’ve sorted out the warnings, then you can worry about reading the log messages.

1 Like

I tried and failed. Can you please tell me why this simple command doesnt work?
var btn = document.getElementById(“btn”);
btn.addEventListener(“click”, function() {
console.log(“Hello”);
});

It doesn’t show anything. Maybe it’s my chrome browser that block something?

The above code does show “Hello” in the browser’s console (Ctrl+Shft+J in Chrome) if you click on the button.

1 Like