Write me the code for a HTML page with a button that when pressed changes the background…
- User
Write me the code for a HTML page with a button that when pressed changes the background color to a random shade of red.
Assistant
Here is the code for a simple HTML page with a button that changes the background color to a random shade of red when clicked:
html<!DOCTYPE html> <html> <head> <script> function changeColor() { var red = Math.floor(Math.random() * 256); var bgColor = "rgb(255, " + red + ", " + red + ")"; document.body.style.background = bgColor; } </script> </head> <body> <button onclick="changeColor()">Change background</button> </body> </html>The key parts:
- The
changeColor()JavaScript function generates a random red shade by picking a random number between 0-255 for the green and blue values (red is fixed at 255).
- The
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.