Question about conversion from celsius to fahrenheit in JS

Im curious about few stuff here. function has the name convertToF, now can we give it any name we want? For example conTF which is more of abbreviation or in any other way? And why is celsius in brackets after function name? Im talking about (celsius) do we put it there just so we want to convert celsius to fahreneit? And what does (celsius) in brackets after function convertToF stand for and is used for? Also, why is celsius inside bracket with * (9/5) in bracket? and why do we need to use + 32 in the end? And what does return statement mean and why is it important? And what does convertToF (30) mean down bellow? I know it says in challenge that we shouldnt worry about functions and statements for now, but im curious as i wish to find out what it all stands for and means. And btw, how we convert specific temperature from fahrenheit to celsius and vise versa?

Im curious about few stuff here. function has the name convertToF, now can we give it any name we want? For example conTF which is more of abbreviation or in any other way?

Yes, but don’t change the names of functions in FCC exercises or your tests will fail.

And why is celsius in brackets after function name? Im talking about (celsius) do we put it there just so we want to convert celsius to fahreneit? And what does (celsius) in brackets after function convertToF stand for and is used for?

That’s what’s called an argument. You’ll learn about them soon if you just keep following the challenges.

Also, why is celsius inside bracket with * (9/5) in bracket?

They’re used to control order of operations, just like in math.

and why do we need to use + 32 in the end?

That’s the formula for converting celsius to fahrenheit.

And what does return statement mean and why is it important?

That’s the output of the function.

And what does convertToF (30) mean down bellow?

That is a call to the function convertToF with 30 being passed as the celsius value that will be converted to fahrenheit.

I know it says in challenge that we shouldnt worry about functions and statements for now, but im curious as i wish to find out what it all stands for and means. And btw, how we convert specific temperature from fahrenheit to celsius and vise versa?

The formula for converting from celsius to fahrenheit is the celsius value times nine, divided by five, plus thirty two.

How do we know that celsius value is 30? I thought celsius value was 32 but it was only a formula for converting. Im kinda confused. I tried changing 32 to other numbers and got different results without any problems or errors, does this mean we can change 32 to any number no problem?

Can we put value of celsius od 30 inside of bracket with * (9/5) ? Because if we calculcate given number of 30 with 9/5 and + 32 in formula we still get 86.

I think you should read about functions in general before worrying about this particular function: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Functions

1 Like

Yeah, it sounds like you’re not quite grasping what functions are. That’s OK, we all have things that are stumbling blocks. You’ll get it if you keep at it. Different people learn differently. I might suggest searching youtube for “javascript function” - sometimes seeing it will help.

To try and answer your question, you can put whatever you want in the parentheses (what you are calling “brackets”) in the function call. Don’t confuse that with the function definition.


// This is the function definition.
// It doesn't do anything until called.
function convertFromCToF(celsius) {
  var fahrenheit;
  
  fahrenheit = (celsius * (9/5)) + 32;
  
  return fahrenheit;
}


// Below are function calls.
// Each calls the function with whatever value you give it..
// and returns a result.

console.log(convertFromCToF(0))
// returns -> 32

console.log(convertFromCToF(-12.6))
// returns -> 9.32

console.log(convertFromCToF(37))
// returns -> 98.60000000000001

console.log(convertFromCToF(30))
// returns -> 86

The number inside the function definition must be 32 because that is how we convert. The number 30 in the example is the temperature they want converted.

2 Likes

Thank you very much for your help, now i understood it completely, i’ll be checking out more stuff about functions in JS on YouTube. I did some practice alone as well and now i understand this all. Thank you for your explanation as well it realy helped me.

Somehow i got confused with this task, you must declared celsius, but with what ?

I’m sorry, I don’t understand your question. It’s not that you " must declared celsius". The celsius value is passed to the function.

In the example I gave above,

convertFromCToF(0)

is what passes the number 0. Then it is received in the function above:

function convertFromCToF(celsius) {
//...

Here the function knows that it is receiving a number and I am telling it that I want it called “celsius”. I could have called it “elephantPajamas”, but “celsius” makes more sense.

Does that clear it up? If not, please rephrase your question and tell us exactly what is confusing you.

thanks for explaining, i cant pass this test because small mistake, expect to write celsius, i was wrote celcius.