Home > Enterprise >  Why is my date not printing to HTML document
Why is my date not printing to HTML document

Time:10-29

`

 let CurrDay = new Date("2022-10-28");
let formattedDate = Intl.DateTimeFormat('en-us').format(CurrDay);
console.log(formattedDate)
let el = document.getElementById("date").innerHTML;
el.innerHTML = formattedDate; 



`

Why is my code not printing to my HTML document? Thank you.

CodePudding user response:

Solution:

You have to use this code:

let CurrDay = new Date("2022-10-28");
let formattedDate = Intl.DateTimeFormat('en-us').format(CurrDay);
console.log(formattedDate);
document.getElementById("date").innerHTML = formattedDate; 

Errors in your code:

JavaScript is case-sensitive. There is nothing like getElementbyId or innerHtml. Those should be getElementById and innerHTML.

CodePudding user response:

let el = document.getElementbyId("date").innerHtml;

  • Related