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!
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
Max Kusnadi
4,368 PointsJS Basic Challenge Task 2
Why my code does not pass? It seems that my Task 1 does not pass after I put this code on my JS file. FYI, I put the script tag in the body, right after div
<!DOCTYPE html>
<html lang="en">
<head>
<title> JavaScript Foundations: Variables</title>
<style>
html {
background: #FAFAFA;
font-family: sans-serif;
}
</style>
</head>
<body>
<h1 id="title">JavaScript Foundations</h1>
<h2>Variables: Basics</h2>
<div id="container">
This is a div with the id of "container"
</div>
<script src="myscript.js"></script>
</body>
</html>
/* JavaScript Foundations: Variables */
var bgColor = "";
var textColor = "";
var container = document.getElementById('title');
container.style.background = bgColor;
container.style.color = textColor;
bgColor = Blue;
textColor= #FF9933;
1 Answer

Chris Shaw
26,662 PointsHi Max,
The following code is what's causing the issue.
bgColor = Blue;
textColor= #FF9933;
This is invalid JavaScript as all strings (which blue and #FF9933 are) need to be wrapped within single or double quotes to prevent unexpected errors such as the one you're getting with the code challenge. The other issue is you have these values declared in the wrong spot as they're supposed to have been placed in the predefined variables as seen below.
var bgColor = "blue";
var textColor = "#FF9933";
So by the time you get up to task 3 your code should be the following.
var bgColor = "blue";
var textColor = "#FF9933";
var container = document.getElementById('title');
container.style.background = bgColor;
container.style.color = textColor;
Happy coding!