-3

I've been given some Javascript from a colleague (who is currently uncontactable) and I want to know how to actually display the number the javascript is creating on my web page. I've loaded the javascript using

<SCRIPT language=JavaScript src="https://www.mywebsite.com/java/counter.js"></SCRIPT>

However I don't know what html to use to actually give me the result.

var currStr = 0;
var targetStr = 0;
var animTimer = null;

$(document).ready(function() {
    currStr = calculateCups();
    $('.tea-count > .figure').html(currStr.toString().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,"));

    setInterval(anim, 1000);
});

function anim()
{
    targetStr = calculateCups();

    animTimer = setInterval(function()
    {
        if (currStr < targetStr) {
            currStr += 155; 
            $('.tea-count > .figure').html(currStr.toString().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,"));
        }

        if (currStr >= targetStr) {
            clearInterval(animTimer);
        }
    }, 25);   
}

function calculateCups()
{
    var cupsNumber = 165000000;
    var date = new Date();
    var hours = date.getUTCHours()*60*60;
    var minutes = date.getUTCMinutes()*60;
    var seconds = date.getUTCSeconds();

    return Math.round((cupsNumber/86400)*(hours+minutes+seconds));
}

Your help is much appreciated!

1 Answers1

0

You could ask your friend or just add this to the end of your webpage before the closing </body> tag:

<script>Your code</script>

Stackgeek
  • 227
  • 1
  • 12