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 JavaScript Basics (Retired) Storing and Tracking Information with Variables Working with Strings and Finding Help

Alternative solution to 'Working With Strings...' Shout app

I stopped the video before Dave provided the solution to the Shout App example and had a go with this result -

var shout = prompt("What would you like to shout?");
alert(shout.toUpperCase() + "!!!");

I really like how Dave broke down the problem by using a methods he had already introduced -

var whatToShout = prompt("What would you like to shout?");var shout = whatToShout.toUpperCase();
shout += "!!!";

Can someone help me understand the difference between the two - what I might have missed or the disadvantages to my approach?


2 Answers

Steven Parker
Steven Parker
220,925 Points

The only difference is that the latter method constructed the final string separately, so that it is still available after the alert call. Your method is more concise, but the final output string is not retained.

In this case, and in many similar practical situations, retaining the modified string is not needed, so your method is completely adequate and maybe even preferable for its conciseness.

I would never have seen that. Thanks.

So you mean although I captured data in the var 'shout', the output is the var 'shout' plus a modification and not stored anywhere?

I felt I might have missed out on the learning by not breaking it down but I guess I can still apply this in the future, then refine it as I go.