CIS44 - JavaScript Quiz #4
Problem #1: The working version of this code generated the following output:
You need to debug the code so it will produce the correct output once again!
<html>
<head>
<title>Radio
button and array question</title>
<script language="JavaScript">
function
whichOption(radiobutton)
{
optionArray
= new Array(4);
optionArray="Vieira";
optionArray="Grocer";
optionArray="Grocer";
optionArray="Grocer";
optionArray="Arruda";
var
indx = 0;
if
(radiobutton[0].checked == true)
{
indx=0;
}
if
(radiobutton.checked == true)
{
indx=2;
}
if
(radiobutton.checked == true)
{
indx=3;
}
if
(radiobutton[4].checked == true)
{
indx=4;
}
window.document.optionInfo.theAdvisor.value
= optionArray;
}
</script>
</head>
<body>
<h1>Option/advisor</h1>
Check
the type of CIS career option to find out the name of your advisor:
<form
NAME = "optionInfo">
<INPUT
TYPE = "radio" NAME = "radiobutton"
VALUE="multi"> Multimedia and the Internet<BR>
<INPUT
TYPE = "radio" NAME = "radiobutton"
VALUE="web"> Webmaster<BR>
<INPUT
TYPE = "radio" NAME = "radiobutton"
VALUE="prog"> Programming<BR>
<INPUT
TYPE = "radio" NAME = "radiobutton"
VALUE="businfo"> Business Information Systems<BR>
<INPUT
TYPE = "radio" NAME = "radiobutton"
VALUE="net"> Networking<BR>
<INPUT
TYPE = "button" VALUE = "Select Option" onClick =
"whichOption(radiobutton);">
<INPUT
TYPE = "text" NAME = "myAdvisor"
SIZE="30"><BR>
</form>
</body>
</html>
Problem #2: I want to fix the endless loop program so it loops through 5 times and then shows a particular picture (your choice). The program has a few errors. You need to fix it and get it working. The images can be downloaded from:
http://www.pgrocer.net/Cis44/HTML/javascript/path.jpg
http://www.pgrocer.net/Cis44/HTML/javascript/house.jpg
http://www.pgrocer.net/Cis44/HTML/javascript/houseusd.jpg
http://www.pgrocer.net/Cis44/HTML/javascript/snow.jpg
http://www.pgrocer.net/Cis44/HTML/javascript/tree.jpg
http://www.pgrocer.net/Cis44/HTML/javascript/street.jpg
<html>
<head>
<title>Working
with a loop</title>
</head>
<script
language="JavaScript">
fstArray = new Array(5);
fstArray=new Image;
fstArray.src="house.jpg";
fstArray=new Image;
fstArray.src="street.jpg";
fstArray=new Image;
fstArray.src="path.jpg";
fstArray=new Image;
fstArray.src="snow.jpg";
fstArray=new Image;
fstArray.src="tree.jpg";
fstArray=new Image;
fstArray.src="houseusd.jpg";
index=0;
ct=1;
function cycle()
{
if
{
document.rotate.src=fstArray[index].src;
index=index+1;
if (index==6)
{
index = 0;
ct=ct+1;
}
setTimeout("cycle()",1000);
}
else
{
document.rotate.src=fstArray[4].src;
}
}
</script>
</HEAD>
<BODY
onLoad="cycle();">
<IMG
SRC="snow.jpg"
NAME="rotate"
WIDTH=50%
HEIGHT=50%>
</BODY>
</HTML>
Problem #3: Go to http://www.javascriptmall.com/learn/lesson7.htm and retrieve the source for assignment 3. Change the message and see if it works.
Problem #4: Take a page that you have or make up a quick one and when it loads have it show a popup window with some information in the window.
Problem #5: You should debug the following problem. When it works, the output looks like the image below. Please note that the text box contains the sum of the cost for the items checked.
<HTML>
<HEAD>
<TITLE>Check
Pay</TITLE>
<SCRIPT language="JavaScript">
function
whichGift(giftInfo)
var wkCost = 0;
{
if (window.document.giftInfo.pad.checked ==
true)
{
wkCost = 120;
}
if (window.document.giftInfo.camera.checked
== true)
{
wkCost = 500;
}
if (window.document.giftInfo.laptop.checked
== true)
{
wkCost = 1500;
}
if (window.document.giftInfo.checked ==
true)
{
wkCost = 900;
}
window.document.giftInfo.theCost.value =
wkCost;
}
function
clearData(giftInfo)
{
window.document.giftInfo.pda.checked ==
false;
window.document.giftInfo.camera.checked ==
false;
window.document.giftInfo.laptop.checked ==
false;
window.document.giftInfo.desktop.checked ==
false;
window.document.giftInfo.theCost = 0;
}
</SCRIPT>
</head>
<body>
<h1>Gifts:</h1>
Check
the gifts you want:
<FORM
NAME = "giftInfo">
<INPUT
TYPE = "checkbox" NAME = "pda"> Palm Pilot<BR>
<INPUT
TYPE = "checkbox" NAME = "camera"> Digital
Camera<BR>
<INPUT
TYPE = "checkbox" NAME = "laptop"> Laptop
Computer<BR>
<INPUT
TYPE = "checkbox" NAME = "desktop"> Desktop
Computer<BR>
<INPUT
TYPE = "button" VALUE = "Determine Cost" onClick =
"whichGift(giftInfo);">
<INPUT
TYPE = "button" VALUE = "Clear"
onClick="clear(giftInfo);">
<INPUT
TYPE = "text" NAME = "theCost"
SIZE="30"><BR>
</FORM>
</BODY>
</HTML>