Question: Make the following modifications to your bannerads.html page so that it rotates the banner ads as opposed to selecting them at random. First, modify the

Make the following modifications to your bannerads.html page so that it rotates the banner ads as opposed to selecting them at random. First, modify the opening BODY tag (line 22) so that it appears as follows:


The new statement added to the ONLOAD attribute initializes the variable adNum to have the value 0. Next, replace the assignment to adNum in the SelectAd function (line 15) to the following:

adNum = (adNum + 1) % 4;

This statement utilizes the JavaScript remainder operator, %, to calculate a new banner ad number based on the old one. The remainder operator returns the remainder after dividing one number by another. In this case, the value (adNum + 1) is divided by 4 and the resulting remainder is assigned back to adNum. The result is that the variable adNum rotates from 0, to 1, to 2, to 3, and then back to 0 each time the SelectAd function is called:

if adNum=0, (adNum + 1) % 4 → (1 % 4) → 1 since 4 goes into 1 zero times with a remainder of 1

if adNum=1, (adNum + 1) % 4 → (2 % 4) → 2 since 4 goes into 2 zero times with a remainder of 2

if adNum=2, (adNum + 1) % 4 → (3 % 4) → 3 since 4 goes into 3 zero times with a remainder of 3

if adNum=3, (adNum + 1) % 4 → (4 % 4) → 0 since 4 goes into 4 one time with a remainder of 0

Thus, the page rotates between the banner ads named ad0.gif, ad1.gif, ad2.gif, and ad3.gif. Make these two changes to your bannerads.html page and verify that it rotates the banner ads as described?

Step by Step Solution

3.48 Rating (165 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Random Banner Ads function SelectAdo Assumes the banne... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Document Format (1 attachment)

Word file Icon

1409-C-S-O-S(981).docx

120 KBs Word File

Students Have Also Explored These Related Operating System Questions!