JavaScript Problems:

.Problem #1:  This page uses a function and passes it a color.  Code the function and make the page work.

<HTML>

<HEAD>

<TITLE>Changing Color</TITLE>

</HEAD>

<BODY>

<FORM>

<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>

 

Problem #2: This code takes in a password and then checks before opening a page.

<HTML>

<HEAD>

<TITLE>Password</TITLE>

</HEAD>

<BODY>

<H1>Password test!</H1>

<SCRIPT language="JavaScript">

var correctPassword;

var thePassword="student";

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

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.

</SCRIPT>

</BODY>

</HTML>

 

 

 

Problem #3:  In this one I have set up a function that needs to have three numbers passed to it.  You need to insert the line that will call the function and pass it the three numbers.

 

<html>

<head>

<title>Question 3 on functions</title>

<script language="JavaScript">

var theAns = 0;

function theMath (num1, num2, num3)

   {

    theAns = (num1 + num2) * num3;

    return theAns

   }

</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.<br>

<script language="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",""));

 

document.write ("The answer is " + theAns);

</script>

</body>

</html>

 

Problem #4: Redo the example above, but this time pass four numbers.  You want to subtract the second number from the first number.  Then you want to add the third and the fourth numbers together.  Then you want to multiply the results of the subtraction using the first two numbers by the results of the addition using the second two numbers.

 

Problem #5:  Use one of the avgfunc examples (be sure to tell me which one).  Modify it so that you take in on hand, on order and the reorder point for an inventory.  Calculate the number to order by subtracting the sum of on hand and on order from reorder point.  If the number to order is greater than 0, write the number that needs to be ordered, if not write a message saying no order needed.

Problem #6: Fix the math facts program (you can use mathfor1.html, mathfor2.html or mathfor2a.html) so that if the student gives a wrong answer, a while loop will stay there saying no until they get the right answer and then it will give the right answer and move on.