You are nearly there, actually. notice the lines below and above the comments telling you where to change the code? the function is looking for fahrenheit. so if you were to somehow assign the modified value of celsius to fahrenehit…
Good job. You can also do it on a single line. like so:
function convertToF(celsius) {
var fahrenheit;
// Only change code below this line
fahrenheit = (celsius * (9/5)) + 32; // fahenheit = celsius * 9/5 + 32 works too.
// Only change code above this line
return fahrenheit;
}
// Change the inputs below to test your code
convertToF(30);
yup. and honestly, you don’t even need the brackets. JavaScript will do the order of operations correctly as I pointed out in the comment. I just like to use them for clarity’s sake.
So i guess algorithm isn’t too strict in Javascript? I haven’t yet comprehend how this will or can be used in future. I guess I will find out later will I?
Yup. Javascript follows standard order of operations, but even if you aren’t changing the order brackets can be helpful for human clarity. Regarding the usefulness of this challenge. As it’s stated in the instructions, it is mainly to help solidify the concepts you have been learning in the previous challenges. But you might want to keep the F to C formula in your back pocket for when you get to the local weather zipline.
Hi I keep receiving error messages after adding this code:
function convertToF(celsius) {
var fahrenheit;
// Only change code below this line
farenheit = (celsius * (9/5)) + 32;
// Only change code above this line
return fahrenheit;
}
// Change the inputs below to test your code
convertToF(30);
I keep getting these error messages:
convertToF(0) should return a number
convertToF(-30) should return a value of -22
convertToF(-10) should return a value of 14
convertToF(0) should return a value of 32
convertToF(20) should return a value of 68
convertToF(30) should return a value of 86
Based on the previous questions I really think their pushing for an answer like this:
function convertToF(celsius) {
var fahrenheit;
// Only change code below this line
fahrenheit = celsius;
fahrenheit *= 9;
fahrenheit /= 5;
fahrenheit += 32;
// Only change code above this line
return fahrenheit;
}
// Change the inputs below to test your code
convertToF(30);
That being said, the math that others provided makes more sense from a traditional math perspective, and works too.
Yes, believe it or not the answer was SO simple I am new to coding and this problem made me cry. Just keeping it real. But now that I se how simple it was, I now have anew set of eyes when looking at issues with code. Hope this helps!
function convertToF(celsius) {
var fahrenheit;
// Only change code below this line
fahrenheit = celsius*9/5+32;
// Only change code above this line
return fahrenheit;
}
// Change the inputs below to test your code
convertToF(-30);
same here, omg!!! i’ve put a console.log to verify my results and all were correct…
after i saw your post, i realized, that i missed the first “h” in fa–>h<–renheit