skip to Main Content

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


  1. Use any IDE with syntax subscripting
    Your span tag is not closed

    <p><span id="data"  >  </span></p>
    

    And you can use innerText insted of textContent

    Login or Signup to reply.
  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search