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 [radius, setRadius] = useState(''); const [perimeter, setPerimeter] = useState(''); const handleRadiusChange = (event) => { setRadius(event.target.value); }; const calculatePerimeter = () => { if (!isNaN(radius) && radius !== '') { const parsedRadius = parseFloat(radius); const calculatedPerimeter = 2 * Math.PI * parsedRadius; setPerimeter(calculatedPerimeter.toFixed(2)); // Round to 2 decimal places } else { setPerimeter('Invalid input'); } }; return ( <div className='container'> <h2 className='title'>React Js Circle Perimeter Calculator</h2> <label className='label'>Enter the radius of the circle:</label> <input type="number" value={radius} onChange={handleRadiusChange} placeholder="Enter radius" className='input' /> <button onClick={calculatePerimeter} className='button'> Calculate Perimeter </button> <p className='result'>Perimeter of the circle: {perimeter}</p> </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>