Java Script Quiz #3:

 

Question #1: Follow the directions in the code.  Note there is an extra credit component.

 

<?xml version="1.0" encoding="iso-8859-1"?>

<!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" xml:lang="en" lang="en">

<head>

<title>Password question</title>

</head>

<body>

<h1>Password test!</h1>

<script type="text/javascript">

<!--

var correctPassword;

var thePassword="student";

correctPassword=prompt("Please enter password to view this page!","");

//You need to insert a IF statement here to check to see if the //password is correct.  If it is not correct you want to put out an //alert.  If it is correct then you want to go to a

//window.location that is my home page.

//To get extra credit: you should loop and give the user three chances //to get the password correct.  If they get it you should go to my //page, if they do not you should tell them access is denied.  Each //time they try and get it wrong, you should put out a message on the //form or an alert

//-->

</script>

</body>

</html>

 

Question #2:  Fix the math facts program (you can use mathfor1x.html, mathfor2x.html or mathfor2ax.html) so that if the student gives a wrong answer, a while loop will stay at that problem giving an incorrect message until the user enters the correct answer.

 

 

 

Question #3:  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. 

 

<?xml version="1.0" encoding="iso-8859-1"?>

<!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" xml:lang="en" lang="en">

<head>

<title>Check cost</title>

<script type="text/javascript">

<!--

function whichGift(giftInfo)

 {

  var wkCost = 0;

  if (window.document.giftInfo.pda.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.desktop.checked == true)

        {

          wkCost = 900;

        }

  window.document.giftInfo.theCost = 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.value = 0;

 }

//-->

</script>

</head>

<body>

<h1>Gifts:</h1>

Check the gifts you want:

<form  action="#" 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="clearData(giftInfo);">

<input type = "text" name = "theCost" size="30"><br />

</form>

</body>

</html>

 

Problem #4: 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 #5: Do some research and find a JavaScript script that could be incorporated into a web page.  Write a XHTML page to incorporate it.  Modify it and explain it.