Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please I need help with this javaScript code! <!DOCTYPE html PUBLIC \"-//W3C//DT

ID: 3719349 • Letter: P

Question

Please I need help with this javaScript code!

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<title>Image Slideshow</title>

<script type="text/javascript" language="Javascript">

<!-- Hide script from old browsers

myPix = new Array("images/image1.jpg","images/image2.jpg","images/image3.jpg")

thisPic = 0

imgCt = myPix.length - 1

function processPrevious() {

if (document.images && thisPic > 0) {

thisPic--

document.myPicture.src=myPix[thisPic]

}

}

function processNext() {

if (document.images && thisPic < imgCt) {

thisPic++

document.myPicture.src=myPix[thisPic]

}

function processCycle() {

if (document.images) {

thisPic++

if ( thisPic==imgCt)

{thisPic=0

}

document.adBanner.src=adImages[thisAd]

setTimeout("processCycle()", 3*1000)

}

// End hiding script from old browsers -->

</script>

</head>

<body bgcolor="#FFFFFF">

<h1 align="center">US Missions to Mars</h1>

<p align="center">

<img alt="image3" height="183" src="image3.jpg" width="275" />&nbsp;</p>

<h1 align="center"><a href="#">&lt;&lt; Previous</a>&nbsp;&nbsp;<a href="#">Next <a href="#">Cycle &gt;&gt;</a></h1>

</body>

</html>

Explanation / Answer

Try this code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
<html>
<head>
<title>Image Slideshow</title>
<script type="text/javascript">
myPix = new Array("images/image1.jpg","images/image2.jpg","images/image3.jpg");
thisPic=0;
imgCt = myPix.length -1;
function processPrevious()
{
if (document.images && thisPic >0)
{
thisPic--;
document.myPicture.src=myPix[thisPic];
}
}

function processNext()
{
if (document.images && thisPic < imgCt)
{
thisPic++;
document.myPicture.src=myPix[thisPic];
}
}
function processCycle()
{
if (document.images) {
thisPic++;
if ( thisPic==imgCt)
{
thisPic=0;
}
document.adBanner.src=adImages[thisAd];
setTimeout("processCycle()", 3*1000);
}
}

</script>
</head>
<body bgcolor="#FFFFFF">
<h1 align="center">US Missions to Mars</h1>
<p align="center">
<img alt="image3" height="183" src="images/image3.jpg" width="275" />&nbsp;</p>
<h1 align="center"><a href="#">&lt;&lt; Previous</a>&nbsp;&nbsp;
<a href="#">Next</a><a href="#">Cycle &gt;&gt;</a></h1>

</body>
</html>