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

Dillon Lee
Dillon Lee
1,458 Points

I think I went a little overboard...

I feel like I might have over-organized the code that I wrote. I feel like it's usually a good idea to write clear programs, but I don't know whether or not I used conventions that are actually easy to digest for people actually used to reading code.

I was wondering if people could give some (brief) feedback about the readability and logical arrangement of the code I wrote.

For the sake of being able to preview the code all together, I simply dumped the story.js contents directly into the index.html <script> tags. I used http://htmledit.squarefree.com/ but I'm sure you can run it in the treehouse workspace if you like.

Also, while you leave feedback, you should copy-paste whatever story you got out of running my code. I think that'd be fun for everybody ^_~.

Thank you, thank you!~ I look forward to hearing from people soon.

<!doctype html>
<html>
  <head>
    <meta charset=utf-8>
    <title>Mad Glib</title>
    <style>p {font-family: monospace;}</style>
  </head> 
  <body>
    <h2>Mad Glib: The Movie Trailer Generator</h2>
       <script>
//Informs the user about the nature of the program to follow
alert("Salutations and welcome, my friend.\n\n\
Today we will be creating a story together.\n\
I have created a framework for a wonderful new movie intro,\n\
and you get to guide the plot of this exciting film of ours!\n\
Please be creative and follow the prompts as they appear.\n\n\
Also, be sure to have fun and copy-paste your results if you want to share!");

//Prompts the user to enter words for the story
var nounOne = prompt("Please list a POWERFUL GROUP OF PEOPLE in the field below and click \"OK\".");
var adjectiveOne = prompt("Please use an ADJECTIVE which DESCRIBES A POWERFUL THING.").toLowerCase();
var nounTwo = prompt("Please list a POWERFUL LIVING THING.").toLowerCase();
var nounThree = prompt("Please list a QUALITY which POWERFUL THINGS POSESS.").toLowerCase();
var nounFour = prompt("Please list A POWERFUL STRUCTURE.").toLowerCase();
var adjectiveTwo = prompt("Please list an ADJECTIVE which DESCRIBES A TERRIFYING OBJECT.").toLowerCase();
var nounFive = prompt("Please list A MYSTICAL ARTIFACT.").toLowerCase();
var nounSix = prompt("Please list a PLURAL FORM of THE MOST POWERFUL CREATURE.").toLowerCase();
var verbOne = prompt("Please list an INFINITIVE FORM OF A VERB that DESERVES TO BE CELEBRATED. Use the format \"to _____\"");
var nounSeven = prompt("Please list THE COOLEST HOLIDAY.");
var adjectiveThree = prompt("Please list an ADJECTIVE which DESCRIBES SUPER COOL THINGS.");
var storyTitle = adjectiveOne.toUpperCase() + " " + nounTwo.toUpperCase() + " and the " +  adjectiveTwo.toUpperCase() + " " + nounFive.toUpperCase();
var catchPhrase = prompt("Please write a CATCH PHRASE that a SUPER COOL, SUPER POWERFUL PERSON WOULD SAY WHEN THERE'S WORK TO DO.");

//Lets the user know that they are finished typing prompts
alert(
"Thank you for participating! Click \"OK\" to view movie trailer script that we came up  with together! \n\n\
Also, if you would like to see or hack away at any of my programming as it unfolds, feel  free to visit my GitHub at https://github.com/Aggredicus\n\n\
Enjoy your time programming!~"
);

//Structures the story into lines
var lineOne = "In a world... Where " + nounOne + " rule the planet.";
var lineTwo = "Only the most " + adjectiveOne + " " + nounTwo + " can make a difference.";
var lineThree = "To muster the " + nounThree + " necessary to overthrow the " + nounOne + " " + nounFour + ",";
var lineFour = "this " + nounTwo + " must seek out the planet's only remaining " + adjectiveTwo + " " + nounFive + ".";
var lineFive = "Armed with the " + nounFive + " and the " + nounThree + " of one thousand " + nounSix + ",";
var lineSix = "one " + nounTwo + " might be able " + verbOne + ".";
var lineSeven = "This " + nounSeven + ".";
var lineEight = "Get " + adjectiveThree + " for:";
var lineNine = storyTitle;
var lineTen = catchPhrase;

//Combines the various lines into a single story object
var completeStory = lineOne + "<br>" + lineTwo + "<br>" + lineThree + "<br>" + lineFour + "<br>" + lineFive + "<br>" + lineSix + "<br>" + lineSeven + "<br>" + lineEight + "<br>" + lineNine + "<br>" + lineTen;

//Wraps the story in a quickly editable CSS tag
var completeStory = "<p>" + completeStory + "</p>"

//Writes the complete story to the DOM
document.write(completeStory);

//NO LONGER USED
//Prints story to console to check for differences from DOM
//console.log(completeStory);a

    </script>
  </body>
</html>
Gunhoo Yoon
Gunhoo Yoon
5,027 Points

Good:

  1. You put meaningful comments.
  2. You took effort writing it.
  3. Tried to follow convention.
  4. Sharing code.
  5. Running code.

There's nothing wrong with your code in terms of clarity. However, clarity also comes from writing effective code which means taking advantage of goodness in programming language you are using. So you need to learn at least basics such as different data types, control-flow statements, functions etc... Keep this code and try to improve upon what you will learn in future.

3 Answers

This is beautifully written, keep up the enthusiasm and you will make a wonderful programmer.

Dillon Lee
Dillon Lee
1,458 Points

Thank you :D! I feel like I've already come a long way since I posted this. Can't wait to share more!

Lorraine Wheat
Lorraine Wheat
6,083 Points

I couldn't get it to run. Has anyone else been able to?

I just took the actual JS (ignoring the HTML bits) and shoved that into my external JS file. Worked fine

my results from playing with your code, which end up being super funny. I was just throwing random words into and it turned out to make a very funny story. http://screencast.com/t/Va21yznrDPjY

You did a great job writing it, although I thought it was bit long but it ended up being worth it.