Temperature Converter

Write temperature conversion and formatting functions.

Start building, submit solution and get feedback from the community.
2Submit Solution
5 upvotes10 upvotes

Temperature Converter

A temperature widget needs two conversion helpers and one formatting helper. Keep the math separate from the display text so each function has one clear job.

Write these functions:

  • celsiusToFahrenheit(celsius) should convert Celsius to Fahrenheit and return the number.

  • fahrenheitToCelsius(fahrenheit) should convert Fahrenheit to Celsius and return the number.

  • formatTemperature(value, unit) should return display text such as "77 F" or "20 C".

Sample checks:

js
const fahrenheit = celsiusToFahrenheit(25);console.log(formatTemperature(fahrenheit, 'F'));const celsius = fahrenheitToCelsius(68);console.log(formatTemperature(celsius, 'C'));const freezingFahrenheit = celsiusToFahrenheit(0);console.log(formatTemperature(freezingFahrenheit, 'F'));const freezingCelsius = fahrenheitToCelsius(32);console.log(formatTemperature(freezingCelsius, 'C'));

Expected output:

txt
77 F20 C32 F0 C

The conversion functions should return numbers. formatTemperature should return the final string.

Join the Community

roadmap.sh is the most starred project on GitHub and is visited by hundreds of thousands of developers every month.

Rank  out of 28M!

361K

GitHub Stars

Star us on GitHub
Help us reach #1

+90k every month

+2.1M

Registered Users

Register yourself
Commit to your growth

+2k every month

49K

Discord Members

Join on Discord
Join the community

Roadmaps Best Practices Guides Videos FAQs YouTube

roadmap.sh by @kamrify

Community created roadmaps, best practices, projects, articles, resources and journeys to help you choose your path and grow in your career.

ThewNewStack

The top DevOps resource for Kubernetes, cloud-native computing, and large-scale development and deployment.