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 JavaScript Foundations Variables Basics

"myscript.js" not applying changes to background.

As stated before, myscript.js does not apply changes to my index.html document. Here is the html code for index.html:

<!DOCTYPE html>
<html lang="en">
    <head>
     <title> Introduction to Programming</title>
     <style>
       html { 
        background: #FAFAFA;
        font-family: sans-serif;
        }
     </style>
    </head>
    <body>
        <h1> JavaScript Foundations</h1>
        <h2>Variables</h2>

        <div id="myDiv">
            This is a div with the id of "myDiv"
        </div>
        <script src="myscript.js"></script>
    </body>

</html>

Here is the code from myscript.js:

var color = "red";

var myDiv = document.getElementById('myDiv')
myDiv.style.backgroundColor = "black";
myDiv.style.background = "#ffffff";

The documents in question are in the same directory.

Sorry about the formatting, it won't format the html code properly.

Hi Lukas,

For posting code you want to use the backtick. It's located on the same key as the ~ It should be above the tab key.

2 Answers

Taylor Dolan
Taylor Dolan
5,134 Points

Looks like you have everything set up properly, but you're using the wrong keyword to set the font color for myDiv.

Your code looks like this in the relevant section:

myDiv.style.background = "#ffffff";

Instead, it should look like this:

myDiv.style.color = "#ffffff";

The reason it works that way is because "color" is the keyword that you use in CSS when setting that property.

Thanks Taylor,

That did the trick!