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
Random Banner Ads function SelectAdo Assumes the banne... View full answer
Get step-by-step solutions from verified subject matter experts
Document Format (1 attachment)
1409-C-S-O-S(981).docx
120 KBs Word File
