Temperature Conversion

Published by Deep Xavier in

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

The conversion formula:

F = C*9/5 +32 // Celsius to Fahrenheit

K = C + 273.15  // Celsius to Kelvin

Examples

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

convertToTemps(100) ➞ [212.0, 373.15]

convertToTemps(-10) ➞ [14.0, 263.15]

convertToTemps(300.4) ➞ [572.72, 573.55]

Notes

  • Round off results to two decimal places.
  • Return an empty array if K is below zero.
Watch a quick demo on how Edabit works.