Quiz #2 on JavaScript:

 

Problem #1:  Follow the embedded instructions to produce output similar to that shown below.

 

<?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>JavaScript Quiz #2</title>

</head>

<body>

<h2>First question on JavaScript Quiz #2</h2>

<p>Find out if you passed the quiz.  The points for each of the 5 questions is a max of 20. 

A passing grade is 60.<br />

I took in 3 grades, you need to take in two more. Follow the pattern that I used. I took

in the ans and then converted it to a number using parseInt which converts character fields

to numeric and stored it in a field that I originally set equal to 0.  Setting it equal to

0 means it is supposed to be a numeric field that holds a number. Then you need to add up

the points and store the answer in myGrade.  Finally you need to test to see if myGrade is

greater than 60.  Put out an appropriate message for passing and failing as well as the

grade.</p>

 

<script type="text/javascript">

<!--

myGrade = 0;

grade1 = 0;

grade2 = 0;

grade3 = 0;

 

ans1 = window.prompt("Key in first grade","");

ans2 = window.prompt("Key in second grade","");

ans3 = window.prompt("Key in third grade","");

 

grade1 = parseInt(ans1);

grade2 = parseInt(ans2);

grade3 = parseInt(ans3);

 

 

//-->

</script>

<p>This is the end of the program!</p>

</body>

</html>

 

 

 

Problem #2:  As explained in the code, you need to call the function and pass it the three numbers that were taken in with the prompt.  You then need to write the function to add the first two numbers together and multiply the result by the third number.  Then (still inside the function) you need to write the answer with a literal saying that it is the answer.

 

<?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>Quiz #2</title>

<script type="text/javascript">

<!--

function theMath (num1, num2, num3)

   {

 

 

 

   }

//-->

</script>

</head>

<body>

Notice that the function is in the head portion of the program.  Now I want to

pass it three numbers the user inputs so it can do the math. Then I want to write the

answer from the inside the function.<br />

<script type="text/javascript">

<!--

var inNum1 = 0;

var inNum2 = 0;

var inNum3 = 0;

inNum1 = parseInt(window.prompt("Enter the first number",""));

inNum2 = parseInt(window.prompt("Enter the second number",""));

inNum3 = parseInt(window.prompt("Enter the third number",""));

 

 

//-->

</script>

</body>

</html>

 

Problem #3: You need to write the function called newColor which receives the color. You should then use the color to change the background color.

 

<?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>Quiz #2</title>

<script type="text/javascript">

<!--

 

 

 

 

//-->

</script>

</head>

<body>

<form action="#" id = "colors"name="colors">

<input type="button" name="redButton" value="RED" onclick="newColor('red')">

<input type="button" name="orangeButton" value="ORANGE" onclick="newColor('orange')">

<input type="button" name="yellowButton" value="YELLOW" onclick="newColor('yellow')">

<input type="button" name="greenButton" value="GREEN" onclick="newColor('green')">

<input type="button" name="blueButton" value="BLUE" onclick="newColor('blue')">

<input type="button" name="purpleButton" value="PURPLE" onclick="newColor('purple')">

</form>

</body>

</html>