My html doesnt read java script file Can you help me?

Hello. my html doesn t read my java script file. Can you help me or is problem with my program or computer.

my file:

html:

<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Countdown timer</title>
    <link rel="stylesheet" href="style.css">
    <script src="../JS2/script.js"></script>
>
  <h1>Hello poppers</h1>  

    <div class="countdown-container">
     <div class="countwdown-el days-c" >
    <p class="big-text" id="days">0</p>
    <span>days</span>
     </div>

    <div class="countwdown-el hours-c" >
        <p class="big-text" id="hours">0</p>
        <span>hours</span>
    </div>

        <div class="countwdown-el min-c" >
            <p class="big-text" id="mins">0</p>
            <span>mins</span>
             </div> 
        
         <div class="countwdown-el seconds-c" >
             <p class="big-text" id="seconds">0</p>
                <span>seconds</span>
                 
</div>
    </div>
</body>
</html>

my script javascript:

const daysEl = document.getElementById ('days');
const hoursEl = document.getElementById ('hours');
const  minsEl = document.getElementById ('mins');
const secondsEl = document.getElementById ('seconds');
  
const newYears='1 Jan 2022';
  
function countDown(){
  
  const newYearsDate = new Date(newYears);
  const currentDate = new Date();
  const totalSeconds = (newYearsDate-currentDate) / 1000;
    
  const days = Math.floor(seconds / 3600 / 24);
  const hours = Math.floor(totalSeconds / 3600) % 24 ;
  const mins = Math.floor(totalSeconds / 60) % 60;
  const seconds =  Math.floor(totalSeconds) % 60; 
    
  daysEl.innerHTML = days;
  hoursEl.innerHTML =hours;
  minsEl.innerHTML = mins;
  secondsEl.innerHTML = seconds; 
}

First of all there is no connection visible between your html and your JavaScript. Is both in the same file? If so, where is the script tag?
Second, you have a function in your JavaScript code but this function is never called anywhere.

I think that what you are trying to say is that your JavaScript function is not being executed.

See onclick Event. That is one way to get your JavaScript function to be executed.

When the script runs in the HTML file, the only elements that exist are the ones that come before that location.

Move the script to the end of the body, just before the </body> tag, and that should work better for you.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.