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 The Variable Challenge Solution

5 Answers

Steven Parker
Steven Parker
229,695 Points

The "undefined" ones are being used before they get defined. You just need to change the order of lines so everything gets defined before it is used:

var ps = prompt("Write either prof or student");
var thing = prompt("Write a thing");
var adjective = prompt("Write an adjective to describe people");
alert("All Done You Did Good");
var a = ' <h2>There once was a university ' + ps;
var b = ' who hosted an event.  When the event ended everyone got a ' + thing;
var c = ' and all the people were ' + adjective +' .</h2> ';
document.write(a+b+c);

Notice how in this version all the variables set by the prompts are defined first.

Bechir Mihoub
Bechir Mihoub
1,118 Points

It still does not work.

Steven Parker
Steven Parker
229,695 Points

That's the same snapshot as before, where the order of the lines needs to be changed.

Bechir Mihoub
Bechir Mihoub
1,118 Points

I copied the answer but it still does not work.

Steven Parker
Steven Parker
229,695 Points

That's why I suggested making a fresh snapshot, so the current code can be analysed.

Bechir Mihoub
Bechir Mihoub
1,118 Points

I did make a fresh one but I don't understand why it does not work. Could it be the html file?

Steven Parker
Steven Parker
229,695 Points

When you re-make the snapshot it should give you a different link. Say, did you remember to save your changes and refresh your browser?

Bechir Mihoub
Bechir Mihoub
1,118 Points

It works but I tried launching a site with it and it did not work there for some reason..

Steven Parker
Steven Parker
229,695 Points

Can you provide the link to it? I'll be happy to take a look.