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

Tim Zander
Tim Zander
2,994 Points

Is there an issue using this shortened/more efficient way than what was shown in the video by Dave?

In the video, Dave added the exclamation points to the shout variable by using a separate line of code before the alert that alters the Shout THEN created the alert, in turn, giving the shout variable three exclamation points. It was more intuitive for me to cut out the line of code that adds the exclamation points and in turn just simply add the exclamation points to the alert. Example: alert(shout + "!!!"); instead of writing another line of code to add them prior to the alert. Will this method cause issues in the future? I just don't want to create any bad habits that I think are efficient and functional but will cause problems in future lessons/projects!

Thank you!

1 Answer

Steven Parker
Steven Parker
231,275 Points

Your code shows exactly the same thing in the alert as the video example. The difference is that the video example changes the contents of the shout variable and your code does not.

If that variable is never re-used, there's no significant difference between the two methods. But if more code were added that used shout again, the result of the later code would be different. The choice of which way to use would be made based on what that later code was expected to do.

Tim Zander
Tim Zander
2,994 Points

Thank you Steven! That makes perfect sense.