Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript

What was meant to be a love story for my girlfriend turned a bit wrong.. Variable Challenge

So started the Variable Challenge earlier, thought I'd make it a bit more interesting so tailor-made love story for my girl. After going wrong several times and the story changing a bit, it somehow morphed from a love poem to this..

console.log("Start program");
alert("Welcome to the Story Maker");
console.log("Take info for story");
// First part of the story.
var charName = prompt("What is your full name?");
var charNickname = prompt("What do you prefer to be called?");
var birthCity = prompt("Where are you from?");
var adjective1 = prompt("Please enter an adjective.");
var adjective2 = prompt("Please enter another adjective.");
var adjective3 = prompt("Please enter a final adjective.");
var verb1 = prompt("Please enter a verb.");
var verb2 = prompt("Please enter another verb.");
var message = ("There ") + ("once ") + ("was ") + ("a ") + ("beautiful ") + ("girl ") + ("called ") + charName + (", ") + ("but ") + ("everyone ") + ("called ") + ("her ") + charNickname + (" she ") + ("came ") + ("from ") + ("a ") + ("place ") + ("faraway ") + ("called ") + birthCity + (". ") + charNickname + ("'s ") + ("favourite ") + ("thing ") + ("to ") + ("do ") + ("was ") + verb1 + (" while ") + ("farting ") + ("really ") + ("loudly ") + ("or ") + ("doing ") + ("a ") + ("poo. ") + ("One ") + ("day ") + ("after ") + ("a ") + adjective2 + (" poo, ") + charNickname + (" decided ") + ("to ") + ("move ") + ("to ") + ("Liverpool ") + ("where ") + ("she ") + ("met ") + ("a ") + adjective1 + ", " + adjective3 + (" fella ") + ("called ") + ("Dean, ") + ("who ") + ("loved ") + ("her ") + ("more ") + ("than ") + ("anything ") + ("and") + ("they ") + ("lived ") + ("happily ") + ("ever ") + ("after.");

// **** EXAMPLE OF STORY *****
// There once was a beautiful girl called Codruta, but everyone called her Cody she came from a place faraway called Romania. Cody's favourite thing to do was "swimming" while farting really loudly or doing a poo. On one day after a "hard" poo, Cody decided to move to Liverpool where she met a "smart", "handsome" fella called Dean, who loved her more than anything and they lived happily ever after.

//Start of document write
console.log("Execute program.");

document.write(message);

console.log("End of story");

alert("The End. Hope your enjoyed your story");

console.log("End program.");
//---------------------------------------------------------------------------

Moderator edited: Added markdown so the code will render properly in the forums. -JN :sparkles:

Luckily, we started learning coding around the same time as eachother, although she hasnt made it onto JavaScript yet, she still saw the thought and effort that went in and almost produced a tear (of happiness, i think.) Anyway just thought I'd get involved in the community and share a bit and hopefully make you laugh if not anything else..

Dean

Steven Parker
Steven Parker
220,696 Points

When posting code, always the instructions for code formatting in the Markdown Cheatsheet pop-up below the "Add an Answer" area. :arrow_heading_down:   Or watch this video on code formatting.

And maybe remove the references to :poop::exclamation:

2 Answers

Steven Parker
Steven Parker
220,696 Points

You could make this code a good bit more compact by merging literal strings into a longer string instead of concatenating every individual word. You also don't need to enclose literal strings in parentheses. For example:

var message = "There once was a beautiful girl called " + charName
              + ", but everyone called her " + charNickname 
              + " she came from a place faraway called " + birthCity
// ... etc.

Throwing a few line breaks in now and then can also help readability.

Took one glance at the next video (the solution) and realised the error of my ways, thanks for the help Steven, only seemed right to make the effort to correct my mistake considering you'd made the effort to answer :) :