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 Working with Strings and Finding Help

Is the code that I've written for this a decent alternative.

The code that I wrote for the challenge looks different that the Dave's example and is a bit shorter but appears to achieve the same effect. I would just like verify that this ok.

my code var stringToShout = prompt("SHOUT!"); alert(stringToShout.toUpperCase() + "!");

Here's a snapshot of my workspace if you prefer to view it that way. https://w.trhou.se/lmv7jpo3i7

2 Answers

Steven Parker
Steven Parker
231,236 Points

The main difference is that the video example builds a new variable "shout" that contains the exact string that is shown by the alert box. If you have no need to reference that string later in the program, your method is a good alternative that makes the code more compact and saves the additional variable assignment.

As the courses continue into more complex tasks, you'll often find there may be more efficient solutions than the video examples since those examples are constructed with a primary objective of conveying the concepts clearly.

Awesome. Thanks for breaking that down Steven.