Write indefinite loop inside of input and switch functions?

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!!!
closed account (3CXz8vqX)
Okay... can you explain why you feel the need to use C inside JavaScript...where JavaScript would be in and of itself satisfactory? (Last I checked JavaScript has switches and while loops itself...)
Like I said, I'm strictly a beginner, I was just relaying my instructor's steps. Here they are in more detail:

1. Create an XHTML web page using an external JavaScript file.
2. Write a function that gets input from the user using the correct built-in JavaScript function 'getinput' and save it in a variable with a default value that displays in the input field of the pop-up box.
3. Write a function that uses a switch statement.
4. Use an indefinite loop allowing the user to keep inputting new values. Inside this loop call the input function and the switch function; after each loop the program should ask the user if they want to continue y/n.

This all has to be done to create a simple yet effective UI.

I asked the question the way I did because I had already written the code I have thus far and wanted to know how to finish it with the last step. Hopefully that makes more sense?

Thanks in advance for giving it a second look!
Topic archived. No new replies allowed.