Best practice when writing functions

We have this task:

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 formula mentioned above to help convert the Celsius temperature to Fahrenheit.

I solved it with this:

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

convertToF(30);

But I guess, if we are tlaking in general, I could code similar function without any variables(like below)? What’s the best practice?

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

convertToF(30);

For moderators: should i always blur the code when talking about working solutions like here?

1 Like

In this case, I’d skip the intermediate variable. I tend to only use variables to hold values I use in multiple places. The function name convertCtoF(celsius) gets the idea across, imho.

1 Like

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