import React from 'react';
function StockPriceDisplay({ priceChange }) {
const textColor = priceChange < 0 ? 'red' : 'green';
return (
Price Change:
{priceChange}%
);
}
export default StockPriceDisplay:
import React, { useState } from 'react';
function NonNegativeInput() {
const [value, setValue] = useState(0);
const handleChange = (event) => {
const inputValue = event.target.value;
// Convert to a number, and if it's negative, set it to 0
const numericValue = Math.max(0, parseFloat(inputValue) || 0);
setValue(numericValue);
};
return (
Enter a non-negative number:
type="number"
id="nonNegativeNumber"
value={value}
onChange={handleChange}
/>
Current Value: {value}
);
}
export default NonNegativeInput
adding a minus sign
// Javascript script
// to convert negative number
// to positive number
// Function to convert
// given number to
// positive number
function convert_positive(a) {
return a < 0 ? -(a) : a;
}
//Driver code
let n = -10;
let m = 5;
// Call function
n = convert_positive(n);
// Print result
console.log(n);
// Call function
m = convert_positive(m);
// Print result
console.log(m);
Top comments (0)