screen_rotation
Copied to Clipboard
<!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <script src="https://unpkg.com/react@17.0.2/umd/react.development.js"></script> <script src="https://unpkg.com/react-dom@17.0.2/umd/react-dom.development.js"></script> <script src="https://unpkg.com/@babel/standalone@7.14.7/babel.min.js"></script> </head> <body> <div id="app"></div> <script type="text/babel"> const { useState } = React; function App() { const [inputValue, setInputValue] = useState(''); const [result, setResult] = useState(''); const calculateArea = () => { if (inputValue) { const parsedRadius = parseFloat(inputValue); if (!isNaN(parsedRadius)) { const circleArea = Math.PI * Math.pow(parsedRadius, 2); setResult(`The area of the circle with a radius of ${inputValue} units is ${circleArea.toFixed(2)} square units.`); } else { setResult('Invalid input'); } } else { setResult('Please enter a radius'); } }; return ( <div className='container'> <h1 className='title'>React Js Circle Area Calculator</h1> <label className='label'> Enter the radius of the circle: <input type="number" value={inputValue} onChange={(e) => setInputValue(e.target.value)} className='input' /> </label> <button onClick={calculateArea} className='button'>Calculate</button> <div className='result'> {result && <p className='result-text'>{result}</p>} </div> </div> ); } ReactDOM.render(<App />, document.getElementById("app")); </script> <style> .container { font-family: Arial, sans-serif; padding: 20px; border-radius: 5px; box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.2); max-width: 600px; margin: 0 auto; text-align: center; } .title { font-size: 24px; margin-bottom: 20px; color: #333; } .label { font-size: 18px; display: block; margin-bottom: 10px; color: #555; } .input { width: 100%; padding: 10px; font-size: 16px; border: 1px solid #ccc; border-radius: 5px; margin-bottom: 20px; box-sizing: border-box; } .button { background-color: #007bff; color: #fff; font-size: 16px; padding: 10px 20px; border: none; border-radius: 5px; cursor: pointer; transition: background-color 0.3s ease; } .button:hover { background-color: #0056b3; } .result { margin-top: 20px; } .result-text { font-size: 18px; color: #333; background-color: #fff; padding: 10px; border: 1px solid #ccc; border-radius: 5px; } </style> </body> </html>