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!
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
Chaz Mabry7,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?
Jason AndersTreehouse Moderator 145,854 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.
Thank-you for sharing! Keep coding! :)
Brendan Moran14,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 JanekFront 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.