Need help converting celsius to fahrenheit! (SOLVED)

Need help converting celsius to fahrenheit! (SOLVED)
0

#1

// WHAT I HAVE SO FAR

function convertToF(celsius) {
var fahrenheit;
// Only change code below this line

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

// Only change code above this line
return fahrenheit;
}

// Change the inputs below to test your code
convertToF(-30);
convertToF(-10);
convertToF(0);
convertToF(20);
convertToF(30);


#2

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…


#3

Would it be

fahrenheit=celsius

?


#4

Ah yes, thank you so much!


#5

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);

#6

Perfect! I wasn’t aware you could use brackets like that


#7

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.


#8

And this…

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

…worked too.

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?


#9

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. :wink:


#10

Ah! Thanks for the tip :wink:


#11

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


#12

OOOPS I just realized my mistake. I spelled the word fahrenheit wrong!!! So sorry, I got it to work now! :slight_smile:


#13

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);
convertToF(-10);
convertToF(0);
convertToF(20);

I’m lazy , so I tried the simplest way. hope it will help you guys.


#14

Thank you all this post helped me alot!!


#15

My working solution I did it this way

function convertToF(celsius) {
var fahrenheit;
// Only change code below this line
greatStuff = 9/5;
x = 32;

fahrenheit = celsius * greatStuff + 32;

// Only change code above this line
return fahrenheit;
}

// Change the inputs below to test your code
convertToF(20);


#16

Some how I got lost with the instructions. Thanks for your help! :slight_smile:


#17

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.


#19

Yes, believe it or not the answer was SO simple :slight_smile: 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);


#21

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


#22

Thanks for the post it helped!