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
Kyle Gibbons
1,388 PointsHello All, I'm curious on why the below code is not working?
var noun = prompt('What is your noun?');
var verb = prompt('What is you verb?');
var adjectives = prompt('What is you adjectives?');
var joke = 'What happens when you cross a ' + noun + 'and a ' + verb + 'with three different ' + adjectives;
document.write(joke);
Aaron Martone
3,290 PointsEnsure that you're not rendering in XHTML, as document.write is incompatible with it. Add a <!doctype html> to the page to change that. Secondly, document.write during page load is functional, but still a bad practice. This code causes "blocking", where the page will be inoperable until the prompts are addressed. The document.write, if executed after page load, will in essence re-open the document for writing, causing all previously generated output to be erased as it writes a new document with the content provided. I'd recommend using jQuery to update the DOM (or Vanilla JS, but it's a bit more verbose). Aside from that, can you expound on how the code "is not working"? What did you do? What did you expect? What have you tried?
2 Answers
Brian Steele
23,060 Pointsvar noun = prompt('What is your noun?');
var verb = prompt('What is you verb?');
var adjectives = prompt('What is you adjectives?');
var joke = 'What happens when you cross an ' + noun + ' and a ' + verb + ' with three different ' + adjectives;
document.write(joke);
Your JS runs without errors, but I'd look at some of the spacing when concatenating the noun/verb/adjective vars into the joke var. Treehouse challenges are picky with being exact.
jason chan
31,009 PointsThat code works. Try different browser or clear history.
Simon Coates
28,695 PointsSimon Coates
28,695 Pointsfyi, I think you can attach requests for help to the challenge where you hit the problem. It's going to improve the quality of feedback you get. There's also a syntax so your code displays as code (enclose with 3 backticks before and after your code). I'm told that it doesn't display when writing the question, but when answering or commenting there's a link called 'Markdown Cheatsheet' that explains the syntax. They could make this stuff simpler. A lot of people have issues with the UI for getting help.