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 [decimalInput, setDecimalInput] = useState('14'); const [hexadecimalOutput, setHexadecimalOutput] = useState(''); const convertToHexadecimal = () => { const decimalNumber = parseInt(decimalInput, 10); // Parse the input as a decimal number if (!isNaN(decimalNumber)) { const hexadecimalValue = decimalNumber.toString(16); // Convert to hexadecimal setHexadecimalOutput(hexadecimalValue.toUpperCase()); // Convert to uppercase for consistency } else { setHexadecimalOutput('Invalid Input'); } }; return ( <div className='container'> <h1>React Js Decimal to Hexadecimal Converter</h1> <input type="text" placeholder="Enter a decimal number" value={decimalInput} onChange={(e) => setDecimalInput(e.target.value)} /> <button onClick={convertToHexadecimal}>Convert</button> <div> <strong>Hexadecimal:</strong> {hexadecimalOutput} </div> </div> ); } ReactDOM.render(<App />, document.getElementById("app")); </script> <style> .container { text-align: center; margin: 50px auto; padding: 20px; width: 600px; border-radius: 5px; box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2); } input { width: 100%; padding: 10px; margin: 10px 0; border-radius: 5px; border: 1px solid #ccc; box-sizing: border-box; } button { padding: 10px 20px; background-color: #007bff; color: #fff; border: none; border-radius: 5px; font-size: 16px; cursor: pointer; transition: background-color 0.3s; margin-bottom:10px } button:hover { background-color: #0056b3; } </style> </body> </html>