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

Jim McQuarrie
Jim McQuarrie
10,597 Points

Difference

I wrote my answer prior to the video answer to see if I had it and it worked perfect except my answer is much shorter.

var shout = prompt('Shout here'); document.write(shout.toUpperCase());

Is there anything wrong with writing it the way I did?

2 Answers

Grace Kelly
Grace Kelly
33,990 Points

Hi Jim, there isn't anything wrong with what you did, however your code and the code in the video do two slightly different things:

var shout = prompt('Shout here'); //asks for input
document.write(shout.toUpperCase()); //outputs the shout variable converted to uppercase

Your code works perfectly, the only thing is, it does not store the uppercase value of shout for future reference, this is fine here as it is only used once, but if you were to use it multiple times, it's handy to store it in its own variable, so you don't have to keep using shout.toUpperCase(), which is what the following code does:

var stringToShout = prompt("What should I shout?"); //asks for input
var shout = stringToShout.toUpperCase(); //stores uppercase stringToShout in its own variable shout
alert(shout) //outputs the shout variable

So the only difference is the code in the video stores the uppercase value for future reference whereas yours does not :)

Hope that helps!!

Jim McQuarrie
Jim McQuarrie
10,597 Points

thank you makes perfect sense