Write a React website with a large button in the center that changes the background color
- User
Write a React website with a large button in the center that changes the background color
- Assistant
Here is a sample code for a React website with a large button in the center that changes the background color when clicked:
import React, { useState } from 'react'; import './App.css'; function App() { // Define the current background color using useState const [bgColor, setBgColor] = useState('#ffffff'); // Define the function to change the background color const changeBgColor = () => { const colorList = ['#6a1b9a', '#039be5', '#d81b60', '#00e676', '#c2185b', '#009688']; const randomIndex = Math.floor(Math.random() * colorList.length); setBgColor(colorList[randomIndex]); } return ( <div className="App" style={{ backgroundColor: bgColor }}> <header className="App-header"> <h1>React Website</h1> <button onClick={changeBgColor}>Change Background Color</button> </header> </div> ); } export default App;The
useStatehook is used to define the current background color, which is initially set to white (#ffffff). ThechangeBgColorfunction randomly selects a color from a pre-defined list of colors and updates the state using thesetBgColorfunction.In the render method, the background color is applied to the
divelement using inline styles:style={{ backgroundColor: bgColor }}. The button triggers thechangeBgColorfunction when clicked.Note: The
App.cssfile can be used to add styles to the website, but it is not required for this example. - User
Generate random programming project ideas
- Assistant
Sure, here are five random programming project ideas:
- Password Manager: Create a program that generates, stores and manages secure passwords for users.
- Recipe App: Develop an app that allows users to search for recipes, create their own recipe collection, and share recipes with others.
- Fitness Tracker: Create an app that tracks user fitness progress, including calorie counting, exercise tracking, and health goals.
- Cryptocurrency Portfolio Manager: Build an application that tracks a user's cryptocurrency investments, including real-time value, price changes, and portfolio performance.
- Social Network: Develop a social network platform where users can connect, share content, and interact with each other. Add features such as chat, messaging, and notifications.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.