Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Here's the code to prompt the user to input a color for the background of the page and set it using JavaScript:

var bgColor = prompt("Please enter a color for the background:");

if (bgColor !== null) {
  document.body.style.backgroundColor = bgColor;
}

This code will display a popup window asking the user to input a color. If the user clicks "Ok," the color entered by the user will be set as the background color of the page. If the user clicks "Cancel" or enters an invalid color value, nothing will happen.