Skip to content
Exercise · Variables and types · lesson 8 of 9

Exercise: Fahrenheit

Write a function function toFahrenheit(c) that converts the temperature c from degrees Celsius to degrees Fahrenheit by the formula F = C × 1.8 + 32.

  • toFahrenheit(100) → 212
  • toFahrenheit(-40) → -40
  • toFahrenheit(36.6) → 97.88

Constraints: c is a number, whole or fractional, not below absolute zero, -273.15; the result is compared with the expected one to within 0.000000001. The tests write it as Math.abs(got - 212) < 1e-9: 1e-9 is 0.000000001, Math.abs drops the sign of the difference, and < means "less than".

Do not add extra imports unless the task says so explicitly.

fahrenheit.js — javascript
javascript · 4 lines
Ctrl+Enter run · Esc leave editor

Subscribe to take the course

The course is free. Sign in with Telegram and subscribe to the channel to open every lesson.

Sign in another way