Convert Celsius to Fahrenheit
To test your learning, you will create a solution "from scratch". Place your code between the indicated lines and it will be tested against multiple test cases.
The algorithm to convert from Celsius to Fahrenheit is the temperature in Celsius times 9/5, plus 32.
You are given a variable celsius representing a temperature in Celsius. Use the variable fahrenheit already defined and apply the algorithm to assign it the corresponding temperature in Fahrenheit.
Note:
Don't worry too much about the function and return statements as they will be covered in future challenges. For now, only use operators that you have already learned.
The code at the start of the challenge:
function convertToF(celsius) {
var fahrenheit;
// Only change code below this line
// Only change code above this line
return fahrenheit;
}
// Change the inputs below to test your code
convertToF(30);
There is the function declaration of function convertToF(celsius) {
.. You have a function name of convertToF
and a parameter of celsius
Parameters are used just like variables. So, inside of the function you can use celsius
JUST like any other variable.
If I have this code:
function addThree (num) {
var result;
result = num + 3;
return result;
}
So, when we make the function call of:
addThree(10);
You're calling the function addThree
You're also passing a value 10
as an argument.
In the function declaration of function addThree (num) {
You see that there is a parameter defined of num
When we do addThree(10)
then the value of the parameter num
is passed the argument value of ... 10
Then if you follow the code through.. result = num + 3;
... and we know the value of num
is 10
.
Therefore, if we follow through the function we end up with ... result = 10 + 3;
then result = 13;
then we return the result
.
If you then make another function call..
addThree(39);
You can use the same function to follow the operation:
When we do addThree(39)
then the value of the parameter num
is passed the argument value of ... 39
Then if you follow the code through.. result = num + 3;
... and we know the value of num
is now 39
.
Therefore, if we follow through the function we end up with ... result = 39 + 3;
then result = 42;
then we return the result
.
If you make the function call of addThree(21)
the value of num
inside the function is 21
.
If you make the function call of addThree(1000)
the value of num
inside the function is 1000
.
If you make the function call of addThree(123456)
the value of num
inside the function is 123456
.
function declaration of function convertToF(celsius) { }
making the function call convertToF(55)
the parameter celsius
inside of the function has a value of 55
function declaration of function convertToF(celsius) { }
making the function call convertToF(23)
the parameter celsius
inside of the function has a value of 23
The algorithm to convert from Celsius to Fahrenheit is the temperature in Celsius times 9/5, plus 32
Spoiler Alert:
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Fahrenheit is the temperature in Celsius times 9/5, plus 32
Fahrenheit is Celsius times 9/5, plus 32
Fahrenheit is Celsius times 9/5 + 32
Fahrenheit is Celsius * 9/5 + 32
....