← Back to challenges

Temperature Conversion

JavaScriptHardnumbersmath

Instructions

Write a program that takes a temperature input in celsius and converts it to Fahrenheit and Kelvin. Return the converted temperature values in an array.

The formula to calculate the temperature in Fahrenheit from Celsius is:

F = C*9/5 +32

The formula to calculate the temperature in Kelvin from Celsius is:

K = C + 273.15

Examples

tempConversion(0) ➞ [32, 273.15]
// 0°C is equal to 32°F and 273.15 K.

tempConversion(100) ➞ [212, 373.15]

tempConversion(-10) ➞ [14, 263.15]

tempConversion(300.4) ➞ [572.72, 573.55]

Notes

  • Return calculated temperatures up to two decimal places.
  • Return "Invalid" if K is less than 0.
javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: The DECIMATOR