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

Chaz Mabry
Chaz Mabry
7,839 Points

Is there anything wrong with doing it this way?

I paused the video once he explain what the app would be to see if I could program it myself. I got the same result but my code looks different:

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

This seams less complicated to me. Is there anything wrong with doing it this way?

3 Answers

Jason Anders
Jason Anders
Treehouse Moderator 145,858 Points

In the real world... no, probably not. You're code is clean and the result is the same.

However, in the challenges, sometimes they are very picky with wording and syntax. So, in the code challenges, if you have problems passing, just try the way it was explained.

In JavaScript, there are often many ways to accomplish the same thing. One is not necessarily better than the other... it's great that you are experimenting and finding new and possibly better ways. Sharing your code with others (and vise-versa) can only make one a better coder!

Thank-you for sharing! Keep coding! :)

Brendan Moran
Brendan Moran
14,052 Points

I had the same question. Seems much simpler to me too. :)

I can see why you might want to make your shout a variable for easier use later on in a more complex code, but I don't see why we would ever want to put the exclamation points in a separate line of code, beyond just demonstrating and reinforcing our memory of +=

In the case of wanting the separate variable for shout I would do

var stringToShout = prompt('What do you want to shout?'); var shout = stringToShout.toUpperCase() + "!!!" alert(shout)

Now you can write your shout to the document or log it to console easily, or quickly use it later in your code for whatever other reason, minus the superfluous line of code that was used to reinforce our memory of +=

Michal Janek
.a{fill-rule:evenodd;}techdegree seal-36
Michal Janek
Front End Web Development Techdegree Graduate 30,654 Points

I used the same 2 line approach but found out that we are using only one variable whereas Dave is creating a new one for future use with uppercase letters. Since it was not asked of us in this video we did not even consider using it and therefore most of us neglected use of 2 variables.