freeCodeCamp/curriculum/challenges/english/02-javascript-algorithms-an.../basic-algorithm-scripting/convert-celsius-to-fahrenhe...

1.8 KiB

id title challengeType isRequired forumTopicId
56533eb9ac21ba0edf2244b3 Convert Celsius to Fahrenheit 1 true 16806

Description

The algorithm to convert from Celsius to Fahrenheit is the temperature in Celsius times 9/5, plus 32. You are given a variable celsius representing a temperature in Celsius. Use the variable fahrenheit already defined and assign it the Fahrenheit temperature equivalent to the given Celsius temperature. Use the algorithm mentioned above to help convert the Celsius temperature to Fahrenheit.

Instructions

Tests

tests:
  - text: <code>convertToF(0)</code> should return a number
    testString: assert(typeof convertToF(0) === 'number');
  - text: <code>convertToF(-30)</code> should return a value of <code>-22</code>
    testString: assert(convertToF(-30) === -22);
  - text: <code>convertToF(-10)</code> should return a value of <code>14</code>
    testString: assert(convertToF(-10) === 14);
  - text: <code>convertToF(0)</code> should return a value of <code>32</code>
    testString: assert(convertToF(0) === 32);
  - text: <code>convertToF(20)</code> should return a value of <code>68</code>
    testString: assert(convertToF(20) === 68);
  - text: <code>convertToF(30)</code> should return a value of <code>86</code>
    testString: assert(convertToF(30) === 86);

Challenge Seed

function convertToF(celsius) {
  let fahrenheit;
  return fahrenheit;
}

convertToF(30);

Solution

function convertToF(celsius) {
  let fahrenheit = celsius * 9/5 + 32;

  return fahrenheit;
}

convertToF(30);