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 trialSammuel Nevarez
1,552 PointsIs there a rule of thumb or best practice when adding new instances to a variable by using the += operator?
Instead of breaking down my string in to different sections for stroyMsg, I wrote out the entire thing.
var adj = prompt("Insert an adjective.");
var verb = prompt("Insert a verb.");
var noun = prompt("Insert a noun.");
var words = adj + verb + noun;
console.log(words);
var storyMsg = 'The ' + noun + ' will get up and ' + verb + ' in a ' + adj + ' way.';
document.write(storyMsg);
alert("Your story is ready!");
1 Answer
Chyno Deluxe
16,936 PointsThere is no wrong way to do it, however, readability should always be priority. An alternative way of writing it would be like the example below of any breakdown you choose.
var storyMsg = 'The ' + noun;
storyMsg += ' will get up and ';
storyMsg += verb + ' in a ' + adj + ' way.';
Sammuel Nevarez
1,552 PointsAwesome. Thanks Chyno!
Chyno Deluxe
16,936 PointsChyno Deluxe
16,936 Points//fixed code presentation