Need help understanding the code

function convertToFahrenheit(celsius) {
        return (celsius * 9 / 5) + 32;

      function convertToCelsius(fahrenheit) {
        return (fahrenheit - 32) * 5 / 9;

      function convertTemperature(degrees, unit) {
        if (unit === 'C') {
          const result = convertToFahrenheit(degrees);
          return `${result}F`;
        } else if (unit === 'F') {
          const result = convertToCelsius(degrees);
          return `${result}C`;

      console.log(convertTemperature(25, 'C'));
      console.log(convertTemperature(86, 'F'));

Please help me understand how the return statement is working here.

what issue are you having? the return statement has some maths operation to execute, and after the resulting number is calculated, it returns the number resulting from those maths operation

Hello Ilenia,

Thanks for replying, I am just a beginner and I can not understand how the output is showing in this code, can you please explain how the result is getting printed step by step if possible.


why don’t you try to explain it yourself at the best of your abilities?

Thank you for replying,

I will go through the code and try to understand how the code is working.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.