-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!

3
  • Refer this link stackoverflow.com/questions/17753241/… Commented Jul 25, 2017 at 11:26
  • have you tried using <code></code> tags? Commented Jul 25, 2017 at 11:29
  • 1
    are you asking how to execute it or how to display it? Firstly ask your colleague what to do. Secondly study Javascript if you don't understand the code. Commented Jul 25, 2017 at 11:31

1 Answer 1

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>

Sign up to request clarification or add additional context in comments.

4 Comments

I've added the code to the page already with the tag "<SCRIPT language=JavaScript src="tea.co.uk/js/counter.js"></SCRIPT>" however I don't know how to actually pull the number the javascript is meant to be generating.
You should paste your html code so we could help you.
I dont have any at all...
Your code actually refers to html elements. You should create the html elements being indexed by your javascript code. Ask your friend to send you the belonged html file.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.