So I'm trying to build a website from scratch as a way to refine my HTML/CSS skills and learn some JavaScript on the way. I have a fair amount of background in HTML/CSS, so thankfully, those aren't giving me too much of an issue - but the JavaScript is uncharted territory for me. In short, I'm trying to have my landing page display the current date/time, but I've been working on and off with this issue for about a week now and I've hit roadblock after roadblock. I've pieced together two different scripts that would make Dr. Frankenstein proud - and one of them does work but only spits out the UTC time standard, which is ugly but usable at least. The other, which would parse the string and all that jazz to make it look nice (Sunday, October 19th, 2017 opposed to Sun Oct 19 2017) refuses to work, however.
Could anyone point me in the direction of what I'd need to put in my LandingPage.html or what I need to fix in my .JS to get it to work?
Here's what I have for the JS, my unedited stream of consciousness comments and all. (Unfortunately I deleted the HTML I DID have for it when I got the other one to work.)
//|------ Date ------|
//Month/Date/Year for Landing Pad (And other pages).
var months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]; //Array for the 12 months in the Julian (that's the one we use right??) calendar, otherwise you'd just have an integer output for the month, which is all well and good when you have a standardized numerical format like 9/10/1996, wherein you read it Month/Day/Year - so September. Specifically September 10th, 1996. But in the UK that'd read October 9th, 1996 because they use Day/Month/Year. So yeah, it's getting spelt out completely.
function getDayOfWeek(date) { //// Accepts a Date object or date string that is recognized by the Date.parse() method.
var dayOfWeek = new Date(date).getDay();
return isNaN(dayOfWeek) ? null : ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'][dayOfWeek];
}
//Array for the 7 days. You should know why from reading the comment on 'var months ='.
var n = new Date(); //Constructor. Without this, we'd just be looking at a string. The horror. Date() without new preceding has no arguments and will just spit out a string. Neato. 'new Date()' allows for a new 'Date' object to be created with whatever parameters. I've got word/typing satiation for the word date now.
var y = n.getFullYear(); //Variable to pull the full current year. (Wya John Oliver?)
var m = n.getMonth(); //Variable to pull the month.
var d = n.getDate(); //Variable to get the numerical date for the month.
document.getElementById("date").value = "It is" + " " + getDayOfWeek(new Date()) + ", " + months[m] + " " + d + ", " + y; //Spits out something like October 9 2017. Sadly no ordinals, at least not today. My head hurts too much right now for that.
//|------------------|
Thanks guys!