I am a beginner student in javascript and html. I am supposed to use/write an indefinite loop allowing the user to keep inputting new values. inside this loop, i am supposed to call my input function and my switch function. After each loop, the program has to ask the user if they want to continue, y/n.
I apologize that it is messy, but here is the code I have so far:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="
http://www.w3.org/1999/xhtml">
<head>
<title>Let's Work with Colors</title>
<script type="text/javascript">
//<![CDATA[
function getFavColor(userInput)
{
//document.write("Default getFavColor( )<br />");
switch(userInput)
{
case "Black":
document.write("Not a common choice<br />");
case "Blue":
document.write("A more popular choice as well as a primary color<br />");
break;
case "Green":
document.write("The color of spring grass<br />");
break;
case "Light Blue":
document.write("The color we see in the spring sky<br />");
break;
case "Orange":
document.write("Also a delicious citrus fruit<br />");
break;
case "Purple":
document.write("My personal favorite<br />");
break;
case "Red":
document.write("The color that means, STOP<br />");
break;
case "Silver":
document.write("Like a shiny new car<br />");
break;
case "Yellow":
document.write("The color of those pesky dandilions<br />");
break;
case "White":
document.write("The color of clouds<br />");
} // end of switch(userInput)
} // end of getFavColor( )
//]]>
</script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<h1></h1>
<script type="text/javascript">
//<![CDATA[
var userInput = "Blue";
while(true) {
userInput = prompt("what is your Favorite Color?", "Blue");
if (color == "Blue") {
document.write("Default input was: " + userInput + "<br />");
getFavColor(userInput);
//]]>
</script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Let's work with colors:</title>
<script type="text/javascript">
//<![CDATA[
<!-- Begin
function color() {
document.bgColor=(""+ colc.cc.value +"");
document.body.text=(""+ colc.tc.value +"");
}
// End -->
</script>
<div align="center">
<form name="colc">
<table border="1">
<td colspan="2">
<b><center>Please Enter a Color</td><tr><td>
<b>Background:</td><td><select name="cc" size="1">
<option value="black">Black
<option value="blue">Blue
<option value="green">Green
<option value="skyblue">Light Blue
<option value="orange">Orange
<option value="purple">Purple
<option value="red">Red
<option value="silver">Silver
<option value="Yellow">Yellow
<option selected value="white">White
</select></td><tr><td>
<b>Text:</td><td>
<select name="tc" size="1">
<option selected value="black">Black
<option value="blue">Blue
<option value="green">Green
<option value="skyblue">Light Blue
<option value="orange">Orange
<option value="purple">Purple
<option value="red">Red
<option value="silver">Silver
<option value="Yellow">Yellow
<option value="white">White
</select>
</td><tr><td colspan="2">
<center><input type="button" name="button" value="Change Color!" onclick="color()">
</td>
</table>
</form>
</div>
<!-- Script Size: 2.08 KB -->
</body>
</html>
Thanks!!!