Convert Celsius to Fahrenheit123

hey every one
i cant under stand this test or it’s answer
convertToF(0) should return a number
convertToF(-30) should return a value of -22
convertToF(-10) should return a value of 14
convertToF(0) should return a value of 32
convertToF(20) should return a value of 68
convertToF(30) should return a value of 86

and the answer
function convertToF(celsius) { var fahrenheit; // Only change code below this line fahrenheit = celsius; fahrenheit*=9; fahrenheit/=5; fahrenheit+=32;

  // Only change code above this line
  return fahrenheit;
}

// Change the inputs below to test your code
convertToF(30);

i cant understand it

Worked fine for me from Chrome DEV console…

Which part do you not understand?

I’m not sure what you don’t understand. Ill give an explanation of my understanding and I hope it helps.

The function is to change the parameter from a value that represents the temperature in Celsius to Fahrenheit.
Then a new variable fahrenheight is created.
Then the variable farenheight is set to stores the value of the parameter passed into the function.
Then farenheight is set to its value multiplied by 9,
farenheight*=9; is the same as farenheight = farenheight * 9;
then fareneheight is set to its value divided by 5,
then farenheight is set to its value plus 32;
then farenheight’s value is returned

If you could be more specific with what it is you don’t understand we can better assist you.

Much simpler and self explanatory is

fahrenheit = celsius * 9/5 + 32;

instead of

1 Like

Doing it this way worked:

function convertToF(celsius) {
var fahrenheit;
// Only change code below this line
y = 9/5;
x = 32;

fahrenheit = celsius * y + x;

// Only change code above this line
return fahrenheit;
}

// Change the inputs below to test your code
convertToF(20);

1 Like

You can reduce the code in single line

fahrenheit = celsius*9/5 +32;