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

Paula Mourad
Paula Mourad
5,154 Points

JS program... My solution :)

Just wanted to share my solution for this program. It works, so I guess that's all that matters! :)

' var adjective = prompt("Please add an ajective."); var verb = prompt("Now, add a verb."); var noun = prompt("Finally, add a noun.");

alert("Are you ready to read your cool crazy story?!");

document.write("There once was a " + adjective + " programmer, who wanted to use JavaScript to " + verb + " the " + noun + "."); '

9 Answers

Miriam Rozenbaum
Miriam Rozenbaum
3,671 Points

Hi guys! I wanted to show you my solution. Its different than the one the teacher posted, but i feel like mine is less confusing to me. I am sure as i progress, I will find the "short cuts" handy but for now, the "long" way makes more sense to me.

var adjective = prompt('Please write an adjective.');

var verb = prompt('Please write a verb.');

var noun = prompt('Please write a noun.');

alert('All done. Ready for the message?');

document.write('<h2>There once was a ' + adjective + ' programmer who wanted to use JavaScript to ' + verb + ' the ' + noun + '.</h2>');

Joshua Clement
Joshua Clement
2,428 Points

I did mine very similarly to yours although I didn't add an h2 tag.

So my code was different than the teachers code as well. I looked at some of the comments and found a good example of why someone might do it differently. Check out the comment/example by Siddharth GS at https://teamtreehouse.com/community/my-code-is-working-but-i-dont-store-sentence-in-variable .

Lee Nolan
Lee Nolan
21,690 Points

Yeah that's pretty much it! I cannot think of a better way to do it myself, mine was very similar.

Chris Rodwell
Chris Rodwell
2,855 Points

Ha! This is great! :)

Miriam Rozenbaum
Miriam Rozenbaum
3,671 Points

,Joshua Goodman

I only added the h2 tags because i wanted to lettering on the page to be larger, and more readable.(for me) They are not required at all!

Natacha Schiettekatte
Natacha Schiettekatte
3,331 Points

Hey! These are great, I did a bit of a different sentence than the one provided:

alert("It's story time!") var adjective = prompt("Write an adjective."); var name = prompt("Now add a name in there."); var adjective2 = prompt("Finally give us another crazy adjective."); alert("It's all finito! Ready to see your short story?"); document.write('One ' + adjective + ' day, ' + name + ' rushed to the bus for a ' + adjective2 + ' visit to the zoo.');

constantino co
PLUS
constantino co
Courses Plus Student 1,380 Points

I think the teacher needs to stick to something easier for students to understand just like above comments rather than complicating his script like in the video which makes harder for first timers...

Tomas Novy
Tomas Novy
9,421 Points

And this is my code :-)

var adjective = prompt('Type your adjective');
var verb = prompt('Type your verb');
var language = prompt('Type code programming language');
var sentence = '<h2>There was a ' + adjective + ' programmer, who wanted to use JavaScript to ' + verb + ' the ' + language + '.</h2>';
alert('Your story is ready!');
document.write(sentence);
Margherita Alletto
Margherita Alletto
1,963 Points

I did the same. I wonder if it is a good choice? Any more experienced programmers (or teachers) who could answer the question?

Tomas Novy
Tomas Novy
9,421 Points

Hi Margherita,

After few more months of learning JS, I would write this code in ES6 as below:

const adjective = prompt('Type your adjective');
const verb = prompt('Type your verb');
const language = prompt('Type code programming language');
alert('Your story is ready!');

const sentence =`<h2>There was a ${adjective} programmer, who wanted to use JavaScript to ${verb} the ${language}</h2>`;

// I would not use document.write also, instead of this I would use innerHTML property
document.write(sentence);
Margherita Alletto
Margherita Alletto
1,963 Points

Thank you very much for taking the time to answer! ^_^