0

I found this icon speaker template online and am trying to play with it. I want to display this class after countdown is 0 but it doesn't show up. Where did I do wrong?

<body>
    <div class="cover">
        <span class="icon speaker" style=display:none></span>
    </div>
    <div id="countDownTimer" style=display:none></div>
</body>

<script>
var count = 120;
playInterval = setInterval(function(){
            var now = new Date().getTime();
            count = count - 1;
            if(count > 0){
                document.getElementById("countDownTimer").innerHTML = Math.floor(count/10) + " seconds before the first question!";
            }

            if(count == 0 || count <= 0){

                document.getElementsByClassName("cover").style = "display:block";
                //$(".icon speaker").show();
            }
      }, 100);
}
</script>
Johnny88520
  • 157
  • 4
  • 13
  • 1
    `document.getElementsByClassName("cover")[0].style.display = "block";` – j08691 Oct 04 '17 at 16:29
  • The element with the id `countDownTimer` doesn't exist - so the line `document.getElementById("countDownTimer")` fails with... > Uncaught TypeError: Cannot set property 'innerHTML' of null – Fraser Oct 04 '17 at 16:31
  • @j08691 - the script will fail before it ever reaches that line... – Fraser Oct 04 '17 at 16:32
  • In addition to @j08691 correction, there is also an extra `}` before `` that will cause a syntax error. Also, consider stopping your counter when it's done with `clearInterval(playInterval)` – Mark Oct 04 '17 at 16:35
  • @j08691 it's still not working. – Johnny88520 Oct 05 '17 at 23:32
  • @Fraser I'm sorry. I missed posting that – Johnny88520 Oct 05 '17 at 23:32
  • @Mark_M I think the } should be fine. And I can't do clearInterval because I need some other functions to do after – Johnny88520 Oct 05 '17 at 23:38

0 Answers0