Basic Javascript - celsius to farenheit "Beginner gettin' brain fried" [Solved]

Basic Javascript - celsius to farenheit "Beginner gettin' brain fried" [Solved]
0.0 0

#3

Hi, welcome to coding :smiley: !

Your conversion is correct, but your function is returning the value of the fahrenheit variable (which is undefined in this case).

There are many ways to go around this one. For one, you can change return fahrenheit; to return celsius;.

You can also add fahrenheit = celsius; after the first comment, then replace every celsius afterwards with fahrenheit.

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

return fahrenheit;

This too is nice (as it resembles the conversion formula, but step-by-step is a good start too!):
fahrenheit = (9 / 5) * celsius + 32;


#4

I just completed this so maybe I can give a hint as to how I figured this out.

I too was stumped with this one for a bit until I remembered that unlike normal text, Javascript is read from right to left. The formula (algorithm) they give you is for us to read i.e left to right not the computer. So you need to make the computer be able to read it correctly.

Hope this helps.

Katie


#5

Thanks very much for your help.

I started out with this

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

but that didn’t work or follow the form of the instructions we’d been given so I tried this…

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

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

// Only change code above this line
return fahrenheit;
}
// Change the inputs below to test your code
convertToF(0);

Still no luck. So I tried this …

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

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

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

this …

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

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

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

// Only change code above this line
return fahrenheit;
}
// Change the inputs below to test your code
convertToF(0);

this…

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

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

// Only change code above this line
return fahrenheit;
}
// Change the inputs below to test your code
convertToF(0);

this…

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

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

fahrenheit = celsius;

// Only change code above this line
return fahrenheit;
}
// Change the inputs below to test your code
convertToF(0);

And as you can probably tell … after I’d checked for typos … tried the variations again … went to stackoverflow … tried the variations again … I started to go just a little loopy.


#6

Ok this is probably a really silly point but…

on the first example you didn’t end it with a semi-colon, could that be it?


#7

Actually, semicolons are optional in JavaScript :slight_smile:


#8

Just tried it with a semi-colon just in case. No luck.

I’m assuming I’m doing the correct procedure in terms of … I fill out the code and then place my cursor on the end of convertToF(0); press enter and expect the conversion to appear on the line below.


#9

change the 0 to a celsius temperature for exampe:

convertToF(25);

then run it, hopefully it will work.


#10

I pasted the first example in FCC’s editor and it passed.

(this one)

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

#11

That’s interesting. Maybe I’ve got the only Where’s Wally book that they forgot to put any Wally’s in.

I’ll try rebooting. If that doesn’t work I’ll go to bed. (1am in Australia)

Hey, this was my first ever experience of getting support from an online community and it was magnificent.

Thanks to all.


#12

You just need to press “run tests” once you’ve filled the code out, cursor doesn’t need to be on the end.

It should work, it did on mine.


#13

That was it. I can’t believe it. I thought because it said it would be tested against multiple cases … I was the one to test it against multiple cases … by changing the variable in the brackets each time and pressing enter.

You did it loud librarian.

Wooo Hooo!!!


#14

Glad it’s solved Zucumpkin!


#15

Pretty funny really. I thought my car wouldn’t start 'cause of a problem in the engine but it was 'cause I was turning the key into the lighter socket.

Cheers.


#16

This is awesome! I would nominate this for @P1xt’s forum quote of the day, but I am not @P1xt, so I can’t.

Btw, I am also in Australia (Melbourne), and from what I can tell, there are not too many of us on the forum - so please stick around so I have a timezone buddy :slight_smile:


#18

Hey Jackson.

I’m a Melbournian also. I’ve just gotten into learning to code online in the last few months and I’m loving it. There is however a very particular type of brain inflammation that occurs when you come up against a barrier. Only seconds ago you were Zeus, manipulating the universe with a few taps on your magic button box, and the suddenly without warning you find yourself all alone in a little room like a hungry waif holding a can of baked beens but lacking a can opener. You try to come at it from as many different angles as you can think of but to no avail, and you know that if there was someone experienced beside you they’d just glance over and casually mutter something like “You didn’t put a blip on your blop”, or “You’re zoing doesn’t match your fazong”, and then with one simple adjustment, you’d be off again cruising down the river of creative flow.

Last night was my first experience of turning to the forum for support and it was great. Quite strange. Asking strangers for help. But beautiful too. Hopefully, one day soon I’ll see someone calling for rescue, and I’ll be the one who can say "Have you tried … "

Cheers and no doubt I’ll see you in cyberspace


#19

I took the long way around – look ma, no parenthesis!

var a = 9 / 5;
var b = 32;

fahrenheit = celsius * a + b;


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

this is correct answer.


#21

I’m also new to coding and got stumped on this one. Thanks for all the help!


#22

Capture 1

Hi Fam, seems like i got the code right, but cant seem to go through the other challenges to submit it?

Thanks.


#23