javascriptbeginner10 minutes

Create a Function to Convert Celsius to Fahrenheit

Write a JavaScript function that converts a temperature from Celsius to Fahrenheit.

Challenge prompt

Build a function named `celsiusToFahrenheit` that accepts one parameter: a number representing a temperature in degrees Celsius. Return the temperature converted to degrees Fahrenheit using the formula F = C * 9/5 + 32.

Guidance

  • Recall that the function should take exactly one input parameter representing Celsius temperature.
  • Use the formula F = C * 9/5 + 32 to convert Celsius to Fahrenheit.
  • Ensure the function returns the converted temperature.

Hints

  • Remember to multiply the Celsius value by 9/5 before adding 32.
  • Make sure to return the result from the function instead of just printing it.
  • Test your function with known values like 0°C should return 32°F.

Starter code

function celsiusToFahrenheit(celsius) {
  // Your code here
}

Expected output

celsiusToFahrenheit(0) // 32 celsiusToFahrenheit(100) // 212 celsiusToFahrenheit(-40) // -40

Core concepts

functionsarithmetic operatorsreturn statement

Challenge a Friend

Send this duel to someone else and see if they can solve it.