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 Basics (Retired) Storing and Tracking Information with Variables Create a variable with a string

Error providing variable stored within var player to the .write() method

My code as posted works whenever I run a local version of it from WebStorm. Can anyone tell me why TeamTreehouse's unit tests are returning a failure for my implementation? To me it seems as if I have in fact provided the necessary arguments to the write() method being called on the document object. Is this concatenation bad form in JS?

var player = 'Jasmine';
document.write('<h1>' + player + '</h1>');
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>JavaScript Basics</title>
<script src="app.js"></script>

1 Answer

28,558 Points

Your code is technically fine, but challenges tend to be very strict. You are not supposed to do anything more than the exact thing the challenge asks for.

The challenge only asks for you to write the name of the player to the page, you write the name wrapped in h1 tags. That is enough of a difference to break the challenge checker. If you remove those tags like this:

var player = 'Jasmine';

Then your code will pass. And this concept of doing exactly what is specified in the instructions and nothing more holds true for most of the challenges on Treehouse. As the challenge checker is quite inflexible. This is especially true when it comes to strings, where even a difference in the spacing will often cause your code to be rejected.

Yeah I managed to pass their test cases by doing that; I just like to find various ways I can break their unit tests with edge cases. I noticed it doesn't accept string interpolation either for these very same reasons.

var player = 'Jasmine';
document.write(`<h1> ${player} </h1>`);