Click to See Complete Forum and Search --> : Script Exercise


fw_141
02-22-2004, 04:18 PM
Write a script that:

1)Prompts the visitor for his or her name and assigns it to a variable.

2)Prompt the user for his or her favorite of the following colors: red, green, blue, magneta, yellow, teal, or silver.

3) Use those variables to set the background color of document and to welcome user by name.

Anyone that can help me with this script.

Am having trouble with number 3 especially.

Fred!

Vladdy
02-22-2004, 04:31 PM
Is this some sort of homework or you are seriously considering putting it on your page...???

olerag
02-22-2004, 08:22 PM
Absolutely silly, however....

<html>
<head>
<script type="text/javascript">
function loadDoc() {
var name = "";
var color = "";

while (name.length == 0) {
name = prompt("Enter your name:","");
}

while (color.length == 0) {
color = prompt("What is your favorite color?\n Red, Yellow, Green, Blue, Silver, Teal, or Magenta.", "Red");
}

document.write("<body bgcolor=" + color + ">");
document.write("Welcome " + name);
}
</script>
</head>
<body onLoad="loadDoc()">
</body>
</html>