why my code isn’t working? it doesn’t display nothing…
let todayDate= document.getElementById('data');
let today = new Date();
let weekday= `${today.getDay() < 10 ? "0" : ""}${today.getDay()}`
let day=`${today.getDate() < 10 ? "0" : ""}${today.getDate()}`;
let month=`${(today.getMonth() + 1) < 10 ? "0" : ""}${today.getMonth()}`;
let year=`${today.getFullYear() < 10 ? "0" : ""}${today.getFullYear() + 1}`;
todayDate.textContent = `${weekday} , ${month} / ${day}, ${year}`;
<p><span id="data"</span></p>
2
Answers
Use any IDE with syntax subscripting
Your span tag is not closed
And you can use innerText insted of textContent
Are you saving this code in a .html file and opening it in a browser? If so, it does work
rendering in chrome
p.s. there is a missing closing tag character (
>
) for your span tag. But the browser should have no trouble handling that in this case.