screen_rotation
Copied to Clipboard
<!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <script src="https://cdnjs.cloudflare.com/ajax/libs/react/17.0.2/umd/react.production.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/17.0.2/umd/react-dom.production.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.26.0/babel.min.js"></script> </head> <body> <div id="app"></div> <script type="text/babel"> // Add the import statement for useState hook const { useState } = React; // Define the App component const App = () => { const [randomNumber, setRandomNumber] = useState(null); const generateRandomNumber = () => { const min = 1; const max = 10; const randomNum = Math.floor(Math.random() * (max - min + 1)) + min; setRandomNumber(randomNum); }; return ( <div className="container"> <h3>React Js Generate Random Number Between 1- 10</h3> <button onClick={generateRandomNumber}> Generate Random Number </button> {randomNumber !== null && <p>Random Number: {randomNumber}</p>} </div> ); }; ReactDOM.render(<App />, document.getElementById("app")); </script> <style> body { margin: 0; } .container { max-width: 600px; margin: 0 auto; padding: 20px; font-family: Arial, sans-serif; box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1); position: relative; } /* Styles for the button */ .container button { padding: 10px 20px; font-size: 16px; background-color: #4caf50; color: #fff; border: none; border-radius: 4px; cursor: pointer; transition: background-color 0.3s; } .container button:hover { background-color: #45a049; } /* Styles for the generated number */ .container p { margin-top: 20px; font-size: 18px; color: #333; } </style> </body> </html>