# Convert Celsius to Fahrenheit Challenge as of 7/7/2017

I think the wording of this challenge is very confusing. They want us to convert Celsius to Fahrenheit. But the answer to the Challenge is not completely correct.

The Challenge:

"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."

fahrenheit = celsius;
fahrenheit *= 9;
fahrenheit /= 5;
fahrenheit += 32;

The last paragraph where it says “variable fahrenheit already defined” to me states that in this case we are suppose to use the variable fahrenheit and calculate for celsius. However, the equation to calculate for celsius is not F*9, F/5, and +32 (as suggested by the solution above). So, the wording should be switched here to say “celsius is already defined” because the title of the challenge is to convert celsius to fahrenheit and not fahrenheit to celsius.

The answer to this challenge is not completely correct, to me, unless someone can explain that it is correct. Why are we taking the known variable fahrenheit(but it’s suppose to be unknown hence the challenge to convert celsius to fahrenheit) and using the equation, to calculate fahrenheit, to calculate for fahrenheit when we already know what fahrenheit is.

In the previous paragraph, they state how to calculate fahrenheit, “algorithm to convert from Celsius to Fahrenheit is the temperature in Celsius times 9/5, plus 32”. So, F = C * 9/5 +32. Therefore, the “algorithm” to calculate celsius is C = F - 32 *5/9.

So if we know what fahrenheit is then shouldn’t we calculate for celsius and not fahrenheit again.
And the solution should say “celsius” instead of fahrenheit because the equation being used is for calculating fahrenheit in the case that celsius is defined.

It should look like this:

fahrenheit = celsius;
celsius *= 9;
celsius /= 5;
celsius += 32;

Answer to convert fahrenheit to celsius:

fahrenheit = celsius;
fahrenheit -= 32;
fahrenheit *= 5;
fahrenheit /= 9;

I understand the concept, but this can really confuse some people such as myself, because logically this does not make sense at all. And if all you care about is getting the correct answer, then what’s the point of all of this.

1 Like

The problem statement is fine.

The variable `fahrenheit` is “already defined” because the function has this line

``````var fahrenheit // declares/defines a variable - it is not initialized
``````

The conversion formula needs to be expressed in code in the `convertToF` function - the function has one parameter `celsius` which is the input in this case - this means the function can be called with a value passed in for the `celsius` parameter - so `celsius` is given and needs to be converted to Fahrenheit - the provided `fahrenheit` variable is a convenience - it could be called anything - what matters is the value returned by `convertToF` which ought to be the correct Fahrenheit value for the passed in centigrade value - otherwise the test cases will fail

I would avoid terms like known and unknown - programming language variables may look like variables in math and physics - algorithms may seem like formulas or equations to manipulate or solve for unknowns - it’s better to not get stuck in these analogies

It should definitely not look like this. This assigns `celsius` to `fahrenheit`, then manipulates `celsius`. This code would leave `fahrenheit` untouched.

``````fahrenheit = celsius;
fahrenheit *= 9;
fahrenheit /= 5;
fahrenheit += 32;
``````

This is correct (though ugly). It takes the value `celsius`, which is passed to the function, and converts it to Fahrenheit.

Thanks for your explanation, this makes more sense now. And Thanks for the tip about not getting stuck in math analogies, it may prove to be helpful later down the road for me.

In the previous paragraph, they state how to calculate fahrenheit, “algorithm to convert from Celsius to Fahrenheit is the temperature in Celsius times 9/5, plus 32”. So, F = C * 9/5 +32. Therefore, the “algorithm” to calculate celsius is C = F - 32 *5/9.

And just as a point of math, the last sentence is wrong, because of order of operations. It should be `C = (F-32) * 5/9.

1 Like

Good catch… order of operations ftw

My issue with this challenge is there does not appear to be a single solution that yields all the acceptance criteria at one time (triggering the completion alert: “Submit and got to my next challenge (ctrl + enter)”).
Did anyone figure out a way to get it?

Basically just exactly as written in the description, but in JS. This seems to trip up an awful lot of people, maybe because the first algorithm challenge is the very first time you don’t really get hand-held (so at least it’s doing its job). It’s testing that you understand JS syntax + basic programming concepts (functions) more than anything else I guess: e.g. can a learner translate the very basic formula written down in the description directly into a very basic js function. eg

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

Or similar