-3
<script src="https://raw.githubusercontent.com/mckamey/countdownjs/master/countdown.js"></script>

<script> function getAge (date) { k = countdown(date); } </script>

And it throws an error

countdown is not defined

UPDATE

I downloaded the file to local and, when i tried calling directly it works but doesn't when inside a function.

Mosh Feu
  • 28,354
  • 16
  • 88
  • 135
Rafee
  • 3,975
  • 8
  • 58
  • 88

2 Answers2

1

This is because the raw files that GitHub serves are not set with the right MIME type, and thus the browser does not download them for security reasons.

Instead, make use of a few alternative generous hosts that DO serve it with the correct MIME type.

The one I usually use is githack.com. To use it, just change the githubusercontent in the URL to githack to get:

https://raw.githubusercontent.com/mckamey/countdownjs/master/countdown.js
GregL
  • 37,147
  • 8
  • 62
  • 67
1

I don't get "countdown is not defined", I get "date is not defined". Now that I've had a chance to review the countdown.js file, You are not sending all the parameters to the function:

function countdown(start, end, units, max, digits) {
    var callback;

    // ensure some units or use defaults
    units = +units || DEFAULTS;
    // max must be positive
    max = (max > 0) ? max : NaN;
    //…

First, you need to define "date" or use "new Date()". Second, there are other parameters that need to be set, including the callback and target element to update. I'd suggest reading the documentation here.

Here's the sample from the readme file:

var timerId =
  countdown(
    new Date(),
    function(ts) {
      document.getElementById('pageTimer').innerHTML = ts.toHTML("strong");
    },
    countdown.HOURS|countdown.MINUTES|countdown.SECONDS);

// later on this timer may be stopped
window.clearInterval(timerId);

Finally, you are not actually calling the getAge function anywhere that I can see. You have only defined it. If you run:

getAge(new Date());

You'll get no errors, but it will do nothing, because you have not defined any of the other parameters.

Dexter
  • 795
  • 2
  • 13
  • 27
  • I got this. but i am still curious wihout parameters it should have thrown me error related to function parameter not the function doesnt exist. – Rafee Mar 18 '16 at 07:26
  • Hard to say without seeing how you have it stored, since it is working fine for me. As long as your code is exactly as it appears here, it is not throwing the function not defined error for me. – Dexter Mar 18 '16 at 09:46