Daiaiai
Daiaiai

Reputation: 1089

Function undefined though it works in JSFiddle

I am really just copypasting the exact same "code" of that fiddle: https://jsfiddle.net/7b0ky186/ to my local html-file and have nothing else around it. But while it works nice in JSFiddle I get an error when starting that function within my console saying that Uncaught ReferenceError: CountDownTimer is not defined

What do I do wrong there?

<body>
<a id="startTimer">Start Count Down</a>
<div>Registration schliesst in <span id="displayTimer"></span> minutes!</div>


<script type="text/javascript">
    window.onload = function() {
        var display = document.querySelector('#displayTimer'),
            timer = new CountDownTimer(5),
            timeObj = CountDownTimer.parse(5);

        format(timeObj.minutes, timeObj.seconds);

        timer.onTick(format);

        document.querySelector('#startTimer').addEventListener('click', function() {
            timer.start();
        });

        function format(minutes, seconds) {
            minutes = minutes < 10 ? "0" + minutes : minutes;
            seconds = seconds < 10 ? "0" + seconds : seconds;
            display.textContent = minutes + ':' + seconds;
        }
    };

</script>

Upvotes: 0

Views: 44

Answers (1)

caramba
caramba

Reputation: 22480

On the left side of jsFiddle.org you see "Resources 1". You can click on it which will show all "resources" which are added. You can then copy the links right from there. In this case you need countdowntimer.js

enter image description here

When you have the URL of the missing .js you can add it like so just before your <script> tag

<!-- your HTML goes here -->
<script src="https://cdn.rawgit.com/robbmj/simple-js-countdown-timer/master/countdowntimer.js"></script>
<!-- your <script> and js things go here -->

Upvotes: 3

Related Questions