DEV Community

mahimahi
mahimahi

Posted on

I'm geting this Error while debugging in console like Uncaught TypeError: Cannot set properties of null (setting 'textContent')

<!DOCTYPE html>
<html>
  <head>
    <link rel="stylesheet" href="bomb.css" >
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous" />
    <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js" integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN" crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js" integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV" crossorigin="anonymous"></script>
  </head>
  <body>
    <script src='bomb.js'></script>
    <div class="timer-container">

      <input type="text" class="user-input" id="defuser" />
      <br />
      <img
        src="https://d1tgh8fmlzexmh.cloudfront.net/ccbp-dynamic-webapps/time-bomb-img.png"
        class="bomb-image"
      />
      <p class="timer-display" id="timer">10</p>
    </div>
  </body>
</html>
Enter fullscreen mode Exit fullscreen mode
CSS content:

@import url("https://fonts.googleapis.com/css2?family=Bree+Serif&family=Monoton&family=Open+Sans:wght@400;700&family=Playfair+Display+SC:wght@400;700&family=Playfair+Display:wght@400;700&family=Roboto:wght@400;700&family=Source+Sans+Pro:wght@400;700&family=Work+Sans:wght@400;700&display=swap");

.timer-container {
  background-color: #00bafc;
  padding: 20px;
  text-align: center;
  height: 100vh;
}

.timer-display {
  font-size: 50px;
  color: white;
}

.user-input {
  border-width: 0px;
  border-radius: 4px;
  padding: 6px;
  text-align: center;
}

.bomb-image {
  margin-top: 40px;
  width: 150px;
}
Enter fullscreen mode Exit fullscreen mode
JS content:

let timerEle = document.getElementById('timer');
let countdown = 10;
let intervalId = setInterval(function(){
    countdown = countdown - 1;
    timerEle.textContent = countdown;
},1000);

Can someone help me on this.
Enter fullscreen mode Exit fullscreen mode

Top comments (1)

Collapse
 
mahi86688 profile image
mahimahi

any one can explain what the error in the code.(actually this code is working on web, But it is not working in visual code.