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.development.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/17.0.2/umd/react-dom.development.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"> const { useState } = React; const App = () => { const [numbers, setNumbers] = useState([-1, -5, 3, -10, 7]); const convertToPositive = () => { const positiveNumbers = numbers.map(number => Math.abs(number)); setNumbers(positiveNumbers); } return ( <div className='container'> <h1>React Js Convert Negative Number to Positive Number</h1> <button onClick={convertToPositive}>Convert to Positive</button> <ul> {numbers.map((number, index) => ( <li key={index}>{number}</li> ))} </ul> </div> ); } ReactDOM.render(<App />, document.getElementById('app')); </script> <style> .container { border-radius: 8px; box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.1); padding: 20px; margin: 20px auto; max-width: 600px; text-align: center; } /* Styles for the header */ h1 { font-size: 24px; color: #333; } /* Styles for the button */ button { background-color: #0074d9; color: #fff; border: none; padding: 10px 20px; margin-top: 10px; cursor: pointer; border-radius: 5px; font-size: 16px; } /* Styles for the button on hover */ button:hover { background-color: #0056b3; } /* Styles for the list */ ul { list-style-type: none; padding: 0; } /* Styles for list items */ li { font-size: 18px; margin: 5px 0; color: #555; } </style> </body> </html>