Skip to content
The Chat Archive
gpt-3.5-turbo-0301· OpenAI WildChat-4.8M (AI2)

Write a React website with a large button in the center that changes the background color

  1. User

    Write a React website with a large button in the center that changes the background color

  2. 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 useState hook is used to define the current background color, which is initially set to white (#ffffff). The changeBgColor function randomly selects a color from a pre-defined list of colors and updates the state using the setBgColor function.

    In the render method, the background color is applied to the div element using inline styles: style={{ backgroundColor: bgColor }}. The button triggers the changeBgColor function when clicked.

    Note: The App.css file can be used to add styles to the website, but it is not required for this example.

  3. User

    Generate random programming project ideas

  4. Assistant

    Sure, here are five random programming project ideas:

    1. Password Manager: Create a program that generates, stores and manages secure passwords for users.
    2. Recipe App: Develop an app that allows users to search for recipes, create their own recipe collection, and share recipes with others.
    3. Fitness Tracker: Create an app that tracks user fitness progress, including calorie counting, exercise tracking, and health goals.
    4. Cryptocurrency Portfolio Manager: Build an application that tracks a user's cryptocurrency investments, including real-time value, price changes, and portfolio performance.
    5. 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.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.