/    Sign up×
Community /Pin to ProfileBookmark

can’t get my script to count up.

hi, i’m a student newbie and i have an excercise, which displays two counters from 0 to infinity. i can get it to count only to 1 then it stops. i have tried calling the function again immediately after it has incremented by 1 to get it to keep going, but i’m having problems. at first i used a for loop, then seen that there was no need, i think, so if you can help i would appreciate it right now.

thanks in advance.

here’s the code:

<html>
<head>
<title>Dynamic HTML</title>
<script language=javascript>

var count1=0;
var count2=0;

function counters()
{
setInterval(“counter1(count1)”,1000);
setInterval(“counter2(count2)”,100);
}

function counter1(count)
{
myPara1.style.color=”red”;

myPara1.innerText=++count;

}

function counter2(count)
{
myPara2.style.color=”green”;

myPara2.innerText=++count;

}
</script>
</head>

<body>
<h1 align=center>Dynamic HTML</h1>
<a href=”” onMouseOver=counters()>Move the mouse over here to begin</a>
<p id=myPara1 align=center>Counter 1</p>
<p id=myPara2 align=center>Counter 2</p>
</body>
</html>

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@ziffgoneMar 19.2004 — I think you simply have to change "myPara1.innerText=++count;" to "myPara1.innerText=count[color=red]++[/color];

I believe you just have the ++ on the wrong side of "count".

Regards...
Copy linkTweet thisAlerts:
@SlankenOgenMar 19.2004 — Try to clearly define your operators with spaces:

myPara1.innerText=++count;

should be-

myPara1.innerText = ++count;
Copy linkTweet thisAlerts:
@lahmayesMar 19.2004 — try this.

[code=php]
<html>
<head>
<title>Dynamic HTML</title>
<script language=javascript>

var count1=0;
var count2=0;

function counters()
{
setInterval("counter1(count1)",1000);
setInterval("counter2(count2)",100);
}

function counter1(count)
{
myPara1.style.color="red";

myPara1.innerText = count1++;
}

function counter2(count)
{
myPara2.style.color="green";

myPara2.innerText = count2++;
}
</script>
</head>

<body>
<h1 align=center>Dynamic HTML</h1>
<p><a href="" onMouseOver=counters()>Move the mouse over here to begin</a></p>
<p align="center"> Seconds:</p>
<p id=myPara1 align=center>Counter 1</p>
<div align="center">Tenths:</div>
<p id=myPara2 align=center>Counter 2</p>
</body>
</html>
[/code]
Copy linkTweet thisAlerts:
@solo101111authorMar 19.2004 — Your solutiontion works like a perfetct.

Regards.

solo.
Copy linkTweet thisAlerts:
@lahmayesMar 19.2004 — glad i could help!
×

Success!

Help @solo101111 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...