Celsius, Fahrenheit, and Kelvin inputs that sync and validate
A lab dashboard needs a small widget with three linked temperature fields: Celsius, Fahrenheit and Kelvin. The user can type into any of them, and the other two update right away. Physically impossible temperatures and typos must not overwrite the last good reading.
The starter code includes one constant:
const ABSOLUTE_ZERO_CELSIUS = -273.15;
Kelvin = Celsius + 273.15
Fahrenheit = Celsius × 9 / 5 + 32
Kelvin = (Fahrenheit + 459.67) × 5 / 9
type="text") labelled Celsius, Fahrenheit and Kelvin (a <label> or aria-label). All three start empty.Number():
98.6, not 98.60 or 98.60000000000001). Hide any error.abc or 12a): leave the other two fields unchanged and show Not a number.Below absolute zero.37.50, that field keeps showing 37.50.Type 37 in Celsius Fahrenheit: 98.6 Kelvin: 310.15
Type 0 in Fahrenheit Celsius: -17.78 Kelvin: 255.37
Type -40 in Fahrenheit Celsius: -40 Kelvin: 233.15
Type 0 in Kelvin Celsius: -273.15 Fahrenheit: -459.67
Type 20 in Celsius Fahrenheit: 68 Kelvin: 293.15
Change it to 20x "Not a number", Fahrenheit still 68, Kelvin still 293.15
Change it to -300 "Below absolute zero", Fahrenheit still 68, Kelvin still 293.15
Clear it Fahrenheit and Kelvin are empty, no error
parseFloat('12a') returns 12. Use Number() so the whole text must be a number.-273.15 °C is exactly absolute zero and is valid. Compute Kelvin directly from the typed scale so floating-point error doesn’t push it below 0.-0.The tests find each input by its label (Celsius, Fahrenheit, Kelvin), set its value, fire input and change events, and read the other inputs’ value. You don’t need test ids, specific class names, or an exact HTML structure. They check that:
Number(), so it must be rounded to 2 decimal places.Not a number and Below absolute zero appear on screen only while the current input is invalid.Capitalization and extra spacing don’t matter.