FAQ: Learn HTML: Script - Defer attribute


#1

This community-built FAQ covers the “Defer attribute” exercise from the lesson “Learn HTML: Script”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Web Development

FAQs on the exercise Defer attribute

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!


#2

This question isn’t about the purpose of the exercise. The “defer” tag works fine. The rest of the exercise confuses me. I assume there’s a bug somewhere but I can’t figure out where it is.

In the instructions for this exercise it states

Each script tag re-styles the Codecademy logo, but the turnYellow.js executes last, making the font color 'yellow'

I’m wondering why the script isn’t working (i.e. the font color doesn’t turn yellow). I clicked run, and the code (I didn’t write the code - it was pre-coded) looks like it should work:

var elem = document.getElementById('logo');
   	  elem.style.color = "yellow";

It seems to linked properly in the html file:

<head>
    <link rel="stylesheet" href="style.css">
    <script id="blue" src="turnBlue.js" ></script>
   <script id="yellow" src="turnYellow.js"></script>
  </head>

Anyone know why it doesn’t work?


#3

According to the Chrome Dev Console, the default color is pink, not yellow. Maybe a mistake?


#4

Same bug over here. Would also like to know why it doesn’t turn yellow on a run without the defer tag.

When looking in the console I get the following errors:

api.segment.io/v1/p:1 Failed to load resource: net::ERR_BLOCKED_BY_CLIENT
js-agent.newrelic.com/nr-spa-1118.min.js:1 Failed to load resource: net::ERR_BLOCKED_BY_CLIENT
geo.qualaroo.com/json/:1 Failed to load resource: net::ERR_BLOCKED_BY_CLIENT
api.segment.io/v1/m:1 Failed to load resource: net::ERR_BLOCKED_BY_CLIENT
turnBlue.js:2 Uncaught TypeError: Cannot read property 'style' of null
    at turnBlue.js:2
turnYellow.js:2 Uncaught TypeError: Cannot read property 'style' of null
    at turnYellow.js:2