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

How To Get Current Date

Using JavaScript how can I get the current date, as well as the one two days in advance? So I would want to get something like January 1, January 3.

2 Answers

@john Magee Alright, I've figured it out, thanks. But how can I set the value of a header to the value of a javascript value?

http://www.w3schools.com/jsref/met_element_getelementsbytagname.asp

Though i'd use an ID or name assigned to the header you want to change, and then look up .innerHTML

    var shownDates=document.getElementById("shownDate");
    shownDates.getElementById("shownDate").innerHTML="U";

I have tried the code above, but the button that I click to display the information does not even show up. @johnMagee

First off thank you so much for all the help. I think it covers the document, so does that only mean the document that contains the code? If so how would I reference the html document? @johnmagee

Steven - you're asking questions that would be covered in the right JS couse if you had made it to the point of changing content and learning about it.

The DOM (Document Object Model) is a key principle to understanding how to capture specific parts of a web page and how to manipulate them (be it all one selector, or all one class, or on specific element because of it's ID).

What you should do on your example code that you submitted is write it out the long way - shownDate.getElementById("shownDate") --> what when you write out shownDate in its entirety?

I really do not currently understand what you mean by writing it out the long way? @johnMagee

Steven

Take a look at your code - realize what your variable definition is covering...