BouncingBall Coding problem, need urgent help.
Posted: Fri Mar 01, 2013 5:40 am
Hello Science Buddies Forum.
I am currently working on my science fair project and decided that my experiment was going to be related to the bouncing ball animation experiment--
--Link: https://www.sciencebuddies.org/science- ... background
Now, I am already on the last step, which is trying to make the ball go up and down (the actual bouncing ball). My problem is that the red ball goes just down, never up and down, just down, and this is because i think my coding is wrong somewhere.
Here's my HTML layout:
<HTML>
________________________________________________________________________________________________________________________________________________
<HEAD><TITLE>ScienceFair</TITLE>
<!-- saved from C:\Users\ELECTROSHOP\Desktop\Science Fair Project Idea -->
<!-- When this code is saved as a local file, the preceding line tells Internet Explorer to treat this file according to the security rules for the Internet zone (plus any security rules specific for the Science Buddies website). -->
</HEAD>
<body>
<IMG ID="ball" STYLE="position: absolute; left: 200; top: 200; width: 10; height: 10;" SRC="ball1.gif">
<SCRIPT LANGUAGE="JavaScript1.2">
<!--
var myBall = document.getElementById("ball");
var loc = 200;
setInterval ("myFunction()", 200);
var direction = 0;
function myFunction()
{
if(0 == direction)
{
/* move down */
loc += 10;
if(loc >= 500)
{
/* reached lower limit, change direction */
direction = 1;
}
}
else
{
/* move up */
loc -= 10;
if(loc < {
/* reached upper limit, change direction */
direction = 0;
}
}
myBall.style.top = loc;
}
// -->
</SCRIPT>
My Page
</BODY>
</HTML>
____________________________________________________________________________________________________________________________________
I repeat, the problem is that the red ball is just going down, not up and down.
Thanks for your assistance.
I am currently working on my science fair project and decided that my experiment was going to be related to the bouncing ball animation experiment--
--Link: https://www.sciencebuddies.org/science- ... background
Now, I am already on the last step, which is trying to make the ball go up and down (the actual bouncing ball). My problem is that the red ball goes just down, never up and down, just down, and this is because i think my coding is wrong somewhere.
Here's my HTML layout:
<HTML>
________________________________________________________________________________________________________________________________________________
<HEAD><TITLE>ScienceFair</TITLE>
<!-- saved from C:\Users\ELECTROSHOP\Desktop\Science Fair Project Idea -->
<!-- When this code is saved as a local file, the preceding line tells Internet Explorer to treat this file according to the security rules for the Internet zone (plus any security rules specific for the Science Buddies website). -->
</HEAD>
<body>
<IMG ID="ball" STYLE="position: absolute; left: 200; top: 200; width: 10; height: 10;" SRC="ball1.gif">
<SCRIPT LANGUAGE="JavaScript1.2">
<!--
var myBall = document.getElementById("ball");
var loc = 200;
setInterval ("myFunction()", 200);
var direction = 0;
function myFunction()
{
if(0 == direction)
{
/* move down */
loc += 10;
if(loc >= 500)
{
/* reached lower limit, change direction */
direction = 1;
}
}
else
{
/* move up */
loc -= 10;
if(loc < {
/* reached upper limit, change direction */
direction = 0;
}
}
myBall.style.top = loc;
}
// -->
</SCRIPT>
My Page
</BODY>
</HTML>
____________________________________________________________________________________________________________________________________
I repeat, the problem is that the red ball is just going down, not up and down.
Thanks for your assistance.