/    Sign up×
Community /Pin to ProfileBookmark

Java banner help, newbie

Hello everyone. I am new to the java language. I am currently trying to complete a school assignment that I can not figure out. No I am not trying to have you guys do my work for me. I have been trying everything I can think of but to no avail. Below is a copy of my code so far, along with the external files. Everything works, except what is inside the “ads” div tag. I am trying to use the “rNumber” variable to create random banner line up. At the end of my script I need to put in (The () are just to show variables, and should not be in the final code) <a href=”(rLink)”> <img src=”ad(rNumber).jpeg” alt=”(rAd)”/></a>

Thank you all for any help you can give me. If I left out any necessary information please just let me know

[code]
<?xml version=”1.0″ encoding=”UTF-8″ ?>

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN”
“http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”>

<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<!–
New Perspectives on JavaScript, 2nd Edition
Tutorial 1
Case Problem 2

The Ridgewood Herald Tribune
Author: Scott Shannon
Date: 1/26/11

Filename: front.htm
Supporting files: ads1.jpg – ads5.jpg, ads.js, fp.jpg, front.htm, logo.jpg, random.js,
styles.css
–>
<title>The Ridgewood Herald Tribune</title>
<link href=”styles.css” rel=”stylesheet” type=”text/css” />
<script src=”random.js” type=”text/javascript”></script>
<script src=”ads.js” type=”text/javascript”></script>
</head>

<body>

<div id=”links”>
<h1>Contents</h1>
<p class=”section”>Main</p>
<p class=”linksub”>
<a href=”#”>Home</a><br />
<a href=”#”>Subscriptions</a><br />
<a href=”#”>Contact Us</a><br />
<a href=”#”>News Sources</a><br /><br />
</p>
<p class=”section”>News</p>
<p class=”linksub”>
<a href=”#”>Local</a><br />
<a href=”#”>National</a><br />
<a href=”#”>International</a><br />
</p>

<p class=”section”>Sports</p>
<p class=”linksub”>
<a href=”#”>Baseball</a><br />
<a href=”#”>Basketball</a><br />
<a href=”#”>Football</a><br />
<a href=”#”>Golf</a><br />
<a href=”#”>Hockey</a><br />
<a href=”#”>Miscellaneous</a><br />
</p>

<p class=”section”>Opinion</p>
<p class=”linksub”>
<a href=”#”>Editorials</a><br />
<a href=”#”>Columnists</a><br />
<a href=”#”>Letters</a><br />
</p>

<p class=”section”>Classifieds</p>
<p class=”linksub”>
<a href=”#”>Employment</a><br />
<a href=”#”>For Sale</a><br />
<a href=”#”>Personals</a><br />
<a href=”#”>Real Estate</a><br />
<a href=”#”>Wanted</a><br />
</p>

<p class=”section”>Other</p>
<p class=”linksub”>
<a href=”#”>Business</a><br />
<a href=”#”>Weather</a><br />
<a href=”#”>Entertainment</a>
</p>
</div>

<div id=”main”>
<div id=”ads”>
<script>
var rNumber = randInt(5);
var rAd = adDescription(rNumber);
var rLink = adLink(rNumber);
document.write(“<a href = rLink >”);
document.write(“<img src = “ad”rNumber.jpg alt = rAd/>
document.write(“</a>)
</script>
</div>
</div>

<div id=”request”><a href=”#”>Contact us today to place your ad</a></div>

<p id=”logo”>
<img src=”logo.jpg” alt=”Ridgewood Herald Tribune” />
</p>

<p id=”fp”>
<img src=”fp.jpg” alt=”” />
</p>

<h2>Park Opens</h2>
<p id=”intro”>The <i>Adventure Island</i> theme park opened its doors on
Monday near Ridgewood. The park, one of the biggest in New Jersey, drew
large crowds, but the long lines didn’t deter anyone. “I’ve been watching
them put up the rides over the last year, it’s really exciting to finally
get inside the gates!” said Ridgewood resident, Denise Brooks.</p>

<p class=”cont”><a href=”#”>story continues on page 2…</a></p>

<address id=”footer”>
<b>Ridgewood Herald Tribune</b> &nbsp;&#176;&nbsp; 10010 Atwood Ave.
&nbsp;&#176;&nbsp; Ridgewood, NJ &nbsp; &nbsp; 07451<br />
Phone: (201)555-1101 &nbsp;&#176;&nbsp; Fax: (201)555-1102
</address>
</div>

</body>
</html>

External Java. Title = ads.js

/*
New Perspectives on JavaScript, 2nd Edition
Tutorial 1
Case Problem 2

Function List:
adsDescription
Used to return a description for ad “n”

adsLink
Used to return the URL for ad “n”
*/

function adDescription(n) {
var descrip = new Array();
descrip[1]=”[AD] Diamond Health Club – For all your Health Club Needs”;
descrip[2]=”[AD] Pixal – Quality Digital Equipment and Accessories”;
descrip[3]=”[AD] dHome – Quality Geodesic Domes and Homes”;
descrip[4]=”[AD] Dunston Retreat Center – get away”;
descrip[5]=”[AD] LanGear – Quality Network Solutions for all your Business Needs”;

return descrip[n];
}

function adLink(n) {
var link = new Array();
link[1]=”http://www.diamondhealth.com”;
link[2]=”http://www.pixalproducts.com”;
link[3]=”http://www.dhome.com”;
link[4]=”http://www.dunstonretreats.com”;
link[5]=”http://wwww.langearproducts.com”;

return link[n];
}

External Java. Title = random.js

/*
New Perspectives on JavaScript, 2nd Edition
Tutorial 1
Case Problem 2

Function List:
randInt
Used to return a random integer from 1 to ‘n’

*/

function randInt(n) {
randNum = Math.ceil(Math.random()*n);
return randNum;
}
[/code]

Again. Thanks for any help.

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @terminalcmd 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 5.25,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...