screen_rotation
Copied to Clipboard
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Date Difference Calculator</title> </head> <body> <div id="app"></div> <script src="https://unpkg.com/react@17.0.2/umd/react.production.min.js"></script> <script src="https://unpkg.com/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> <script type="text/babel"> const { useState} = React; function App() { const [value1, setValue1] = useState(30); const [value2, setValue2] = useState(60); const [value3, setValue3] = useState(80); const updateValues = () => { // Generate new values (for demonstration purposes) const newValue1 = Math.round(Math.random() * 100); const newValue2 = Math.round(Math.random() * 100); const newValue3 = Math.round(Math.random() * 100); setValue1(newValue1); setValue2(newValue2); setValue3(newValue3); }; const getColor = (value) => { if (value > 70) { return 'green'; } else if (value >= 30 && value <= 70) { return 'yellow'; } else { return 'red'; } }; return ( <div className='container'> <h3>React Js Change Text Color Based on Value</h3> <button onClick={updateValues}>Change Values</button> <p style={{ color: getColor(value1) }}> Text color based on value: {value1} </p> <p style={{ color: getColor(value2) }}> Text color based on value: {value2} </p> <p style={{ color: getColor(value3) }}> Text color based on value: {value3} </p> </div> ); } ReactDOM.render(<App />, document.getElementById("app")); </script> <style> .container { max-width: 400px; margin: 0 auto; text-align: center; padding: 20px; border-radius: 10px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); } h3 { font-size: 24px; color: #333; margin-bottom: 20px; } button { padding: 10px 20px; background-color: #007bff; color: #fff; border: none; border-radius: 5px; font-size: 16px; cursor: pointer; transition: background-color 0.3s ease; } button:hover { background-color: #0056b3; } p { font-size: 18px; margin-top: 15px; } /* Customize the colors based on your logic */ </style> </body> </html>