Assignment 17 - A Possible Answer

Select a Background Color

To get the effect, you need to insert a prompt before the function, then add the output of the prompt to the alert button. The full document looks like this:

<SCRIPT type="text/javascript">
  var user_name = 
    ("Write your name in the box below","Write it here");

    function newcolor(color)

      alert("Hey " + user_name + "!  You Chose " + color)
<body bgcolor="white">
<center><h1>Select a Background Color</h1>
  <input type="button" 
    value="Blue" onClick="newcolor('lightblue')">
  <input type="button" 
    value="Pink" onClick="newcolor('pink')">

Close this window to return to JavaScript Primer