Unexpected character in Countdownjs

Asked

Viewed 57 times

0

I am using a countdown (countdown) on my page. After some searches I found the Countdownjs. I was following this tutorial until I realized that even without changing anything in the code of the script I downloaded from Official website it displays an error in the console:

inserir a descrição da imagem aqui

There really is a wrong character in the code or is some configuration that needs to be done in the environment?

HTML:

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Countdown</title>
</head>
<body>
    Countdown until 2050  
    <h1 id="countdown-holder"></h1> 

    <script src="countdown.js"></script>
    <script>  
      var clock = document.getElementById("countdown-holder")  
        , targetDate = new Date(2050, 00, 01); // Jan 1, 2050;  

      clock.innerHTML = countdown(targetDate).toString();  
      setInterval(function(){  
        clock.innerHTML = countdown(targetDate).toString();  
      }, 1000);  
    </script> 
</body>
</html>

SCRIPT: https://bitbucket.org/mckamey/countdown.js/raw/tip/countdown.js

  • 1

    in <script src="js/countdown.js"></script> you must not have correctly added the value in src="js/countdown.js", check the actual script path and replace js/countdown.js by it, this error happens because Countdown does not exist yet and you are trying to use it in your code.

  • The path is correct, it’s already been changed! Following your theory, maybe I’m writing in the wrong place, seeing that I use Yeoman and he has some quirks about it. I’ll take a look.

  • that she may be in a different scope

  • No, the error continues! This time I’m sure there’s nothing wrong with the directories and scopes. I remember that this error already occurred when I tried to use this object before the semicolon. I do not understand well! :/

  • 1

    would be able to post the code to analyze?

  • Are you sure the @Silvioandorinha answer solved your problem? Because in practice it doesn’t change your code.

Show 1 more comment

1 answer

0


Here you used comma and the correct one would be point and comma

  var clock = document.getElementById("countdown-holder")  // nessa linha
    , targetDate = new Date(2050, 00, 01); // Jan 1, 2050;  // nessa linha

the correct would be

 var clock = document.getElementById("countdown-holder");  
 targetDate = new Date(2050, 00, 01); // Jan 1, 2050;  
  • The comma is fully valid in the var. In this case your change doesn’t make much difference, but in another scope could be creating a global variable improperly.

  • @bfavaretto is right, so because he gave me a certain?

  • Then I don’t know, you have to ask him :) Oh, if it wasn’t clear, the -1 is mine because the answer transmits incorrect information ok?

  • @bfavaretto yes all right I did not know that with the comma worked normal, but I do not understand that I helped him because he abandoned the question and gave me a right.

  • I asked him upstairs.

  • @bfavaretto I don’t know if this changes a lot but I think he should put the script code and import out of body

  • If he put after the </body> is invalid; if it passes to <head>, will give error in the getElementById. It’s okay like this.

  • @bfavaretto and get him between the head and the body?

  • It is also invalid!

  • @bfavaretto strange because I always made and do so and right.

Show 5 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.