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

Hello all. I’m completely stumped by this. I’ve looked at other people’s chat about this issue and it hasn’t helped me.

I’m completely new to coding. This is the first piece of algorithmic code I have ever attempted. The instructions said to disregard the function aspect and the return aspect as we haven’t covered them yet. We should only use the code forms we had just been learning. I have this feeling I should be doing something with the var fahrenheit; aspect but I really can’t see how to include it.

If anyone’s got a tutor vibe going I’d appreciate it.

Below is my best guess
Cheers

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

Just remember some algebra. If they would tell you that the a is like double b minus c, how you would write this? a = 2 * b - c like that, right. Same is here:
fahrenheit = (whatever actions performed with celsius)

in your attempt you are changing celsius variable itself

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;

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

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.

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?

Actually, semicolons are optional in JavaScript :slight_smile:

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.

change the 0 to a celsius temperature for exampe:

convertToF(25);

then run it, hopefully it will work.

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

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.

1 Like

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.

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!!!

Glad it’s solved Zucumpkin!

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.

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:

1 Like

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

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

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

fahrenheit = celsius * a + b;

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

this is correct answer.

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