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 trialBechir Mihoub
1,118 PointsMy variables are undefined
I can not make my variables defined. https://w.trhou.se/njpgn9zkt0
5 Answers
Steven Parker
231,271 PointsThe "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.
Steven Parker
231,271 PointsThat's the same snapshot as before, where the order of the lines needs to be changed.
Bechir Mihoub
1,118 PointsI copied the answer but it still does not work.
Steven Parker
231,271 PointsThat's why I suggested making a fresh snapshot, so the current code can be analysed.
Bechir Mihoub
1,118 PointsI did make a fresh one but I don't understand why it does not work. Could it be the html file?
Steven Parker
231,271 PointsWhen 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
1,118 PointsIt works but I tried launching a site with it and it did not work there for some reason..
Steven Parker
231,271 PointsCan you provide the link to it? I'll be happy to take a look.
Bechir Mihoub
1,118 PointsBechir Mihoub
1,118 PointsIt still does not work.