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 trialFrank Malcov
Full Stack JavaScript Techdegree Student 38 Pointsdisplaying the code
trying to understand why we dont do just basic displaying this way;
message = <h1>You guessed the number! It was ${randomNumber}.</h1>
;
document.querySelector("main").innerHTML = message
I can see in the video they create variable on the top like this followed by code in the end of the document
const main = document.querySelector('main'); //this is on the top;
main.innerHTML = <h1>You guessed the number! It was ${randomNumber}.</h1>
; //this in on the button
Does it make any difference? when we display the code your way and why did we created variable?
1 Answer
Steven Parker
231,275 PointsThe variable has no effect on delivering the message to the page, but it's useful for setting which message will be shown. Before the last program improvement, only one message was being shown so the variable wasn't needed.