Back to Freecodecamp

Build a Celsius to Fahrenheit Converter

curriculum/challenges/english/blocks/lab-celsius-to-fahrenheit-converter/56533eb9ac21ba0edf2244b3.md

latest1.5 KB
Original Source

--description--

In this lab, you will write a function that converts the temperature from Celsius to Fahrenheit. The formula to convert from Celsius to Fahrenheit is:

js
fahrenheit = celsius * (9/5) + 32

Objective: Fulfill the user stories below and get all the tests to pass to complete the lab.

User Stories:

  1. You should create a function named convertCtoF.
  2. convertCtoF should take a single numeric argument, which is the temperature in Celsius.
  3. convertCtoF should return a number.

--hints--

You should create a function named convertCtoF.

js
assert.isFunction(convertCtoF);

convertCtoF should take a single parameter.

js
assert.lengthOf(convertCtoF, 1);

convertCtoF(0) should return a number.

js
assert.isNumber(convertCtoF(0));

convertCtoF(-30) should return a value of -22.

js
assert.strictEqual(convertCtoF(-30), -22);

convertCtoF(-10) should return a value of 14.

js
assert.strictEqual(convertCtoF(-10), 14);

convertCtoF(0) should return a value of 32.

js
assert.strictEqual(convertCtoF(0), 32);

convertCtoF(20) should return a value of 68.

js
assert.strictEqual(convertCtoF(20), 68);

convertCtoF(30) should return a value of 86.

js
assert.strictEqual(convertCtoF(30), 86);

--seed--

--seed-contents--

js

--solutions--

js
function convertCtoF(celsius) {
  let fahrenheit = celsius * (9 / 5) + 32;
  return fahrenheit;
}

convertCtoF(30);