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 trialUnsubscribed User
4,479 PointsAlternative 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 += "!!!";
alert(shout);
Can someone help me understand the difference between the two - what I might have missed or the disadvantages to my approach?
Thanks.
2 Answers
Steven Parker
231,271 PointsThe 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.
Unsubscribed User
4,479 PointsI 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.