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 trialPaula Mourad
5,154 PointsJS 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
3,671 PointsHi 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>');
Lee Nolan
21,690 PointsYeah that's pretty much it! I cannot think of a better way to do it myself, mine was very similar.
Chris Rodwell
2,855 PointsHa! This is great! :)
Miriam Rozenbaum
3,671 PointsI 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
3,331 PointsHey! 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
Courses Plus Student 1,380 PointsI 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
9,421 PointsAnd 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
1,963 PointsI did the same. I wonder if it is a good choice? Any more experienced programmers (or teachers) who could answer the question?
Tomas Novy
9,421 PointsHi 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
1,963 PointsThank you very much for taking the time to answer! ^_^
Joshua Clement
2,428 PointsJoshua Clement
2,428 PointsI did mine very similarly to yours although I didn't add an h2 tag.
Steve Tenpas
6,234 PointsSteve Tenpas
6,234 PointsSo 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 .