Help with operator (i think) for Kelvin weather project

Link to project

the instructions say to subtract 273 from the kelvin variable to equal celsius. The lessons show to use -= to subtract but that doesn’t work here.

I don’t understand why the code is written this way. const celsius = kelvin - 273;
If we could just write kelvin - 273 and get the answer, why do we need to use -= or whatever these weird backwards math things do in the lesson?

1 Like

It’s probably to get you used to how -=, += and other combos operate.

They are fairly common in code and often (though not always) increase readability and are also quicker to write.

combos? -= and =+= don’t work in this exercise. const celsius = kelvin -= 273;I tried doing it like the instructions in the lesson said but it doesn’t work and I use have to do it the other way like in the hint. I don’t understand why it’s different than what was taught.

By combos I mean the combinations of -=. *=, +=, etc.

I can’t actually access the lesson (because it’s pro) so I don’t know what they’re asking you to do specifically. If you want to post a screenshot or copy and paste I can help you.

const celsius = kelvin - 273; is ok, (it works with the scientific formula)

I can see this being a function

function convertKelvinToCelsius(temperature){
   temperature -= 273
   return temperature

// takes a kelvin temperature and subtracts 273, the return value is the celsius equivalent

@byte5723385929 you can always check MDN, stackoverflow, or reference books (like the free and wonderful ) if you run into stuffy you haven’t seen before.

Thank you for your help. I don’t know what a function is, I’m very new to JavaScript. Here is the code below. I did get it to work but I don’t understand it. I’ve tried looking on stackover flow and other boards but it’s over my head. I know so little I hardly know what to ask for.

// Set kelvin to 293 - stays the same
const kelvin = 293;
// Set celsius to - 273
const celsius = kelvin - 273;
// get farenheit from formula
let fahrenheit = celsius * (9 / 5) + 32;

//Round down the decimal number
fahrenheit = Math.floor(fahrenheit);

let newton = celsius * (33 / 100);

newton = Math.floor(newton);

console.log(`the temperature is ${fahrenheit} degrees Fahrenheit`);

console.log(`the temperature is ${celsius} degrees Celsius`);

console.log(`the temperature is ${newton} degrees Newton`);

Which part didn’t you get?

The part with the math. The lesson says to use this thing (operator?) -= += and the project uses this thing (something else?) const celsius = kelvin - 273; that isn’t explained anywhere.

wouldn’t it be something like const fahrenheit = celsius =- 273 like in the lesson?

This format doesn’t really exist: fahrenheit = celsius =- 273
@byte5723385929 to be clear it should be -= and not =-

it’s either x = x + 1 or x += 1 both say the same thing (add 1 to x). The way to interpret it is that the values on the left side of the = are the ones being changed, the operation on the right are what it is being changed to.

  • In plain english it can be read, the value of x will equal x’s previous value plus one. (x = x + 1)


  • The value of x will increment by 1 (x += 1)

1 = 1 += 2
results in this error
Uncaught SyntaxError: Invalid left-hand side in assignment

1 Like

That part makes sense, and that’s how it’s explained in the lesson. but that’s not how it’s used in the project. It uses variable = othererVariable - 273. I don’t remember learning that format. This is what is so confusing.

Well yes, at any point you will be able to interchange valid variables.

Another way to look at it is that we are doing this

something = something + something

Whether it’s an explicit integer or not, javascript will be ready for a whole range of variables to be given. (And not just numbers).

Interchange valid variables? Where do I learn this? It’s not anywhere in the variable lessons or cheatsheet. Is there other lessons I need to read somewhere else to be able to do these projects?

This would fall under the category of fundamental theory. It’s up to a book to lay that out. Definitely don’t take my word as gospel, I’m just another user :sweat_smile:

@byte5723385929 do check out the eloquent javascript book I linked, it’ll do better to satisfy your more burning questions. Install node.js and run the examples on the terminal as you go through it and you’ll develop stronger intuition for what the fundamentals are.

It’s totally optional though.

I’ve been trying to get through that book, it’s incredibly hard, I can’t remember anything in it but I’m trying.

What exactly do I ned to do/know to learn JavaScript? I tried learning node on another forum but everyone on the node forums tells me to learn javaScript to use node. I still don’t even know what node does. When I tried installing node and my terminal gave me a bunch of errors that i asked for help about, I didn’t understand any of the answers and my terminal still won’t work like it used to.

Should I finish the book before trying and failing intro to javaScript here class again? I’ve repeated the lessons and exercises so much here I have the instructions almost memorized.

No worries, it’s great you’re still keeping at it. Especially if it’s your first language in CS it doesn’t come easy.

I’d say the eloquent book is on the advanced side, but will give you deeper answers when you are looking for them (so definitely don’t try to complete it first).

I think it’s ok at first to go through some exercises even if you don’t fully understand them. Then after a while, come back and try to solve them again. It helps throughout the process to not only take notes about what you’re learning, but also to take notes about what your mental process is while learning. Just be careful not to go too far into the modules leaving things that you don’t understand.

Don’t try to memorize lessons, if you know the answer by heart, try modifying the question so it’s slightly different and see if you can solve that for yourself.

Maybe also try to find some videos that explain things in terms that are clear to you.

1 Like

I’ll try to keep with the exercises. It’s incredibly frustrating to go through all the lessons in the most basic course and not understand or retain anything except the directions. I’ve used HTML and CSS for over 15 years but those actually make sense. I take notes on JavaScript lessons…reviewing them doesn’t really help it.

I don’t know what a mental process is…like what I’m thinking while I’m learning?

I don’t know what a mental process is…like what I’m thinking while I’m learning?

Yea. Some would say to pick something a bit more structured like python. That might help. My issue with javascript is that because it allows for some different things, it creates confusion unless your fundamentals are really solid. I like python as a starting language in that sense because it tends to be more straight-forward (while touching the same concepts). (Javascript wasn’t my first language but I noticed I would get frustrated if it were).

HTML and CSS are simply different beasts. CSS can be really challenging but in a different way. For me, they are almost completely separate in terms of mindset for fixing problems (for me at least). Never do I think that I’m getting better at javascript if I get better at CSS. However, if I get better at Javascript, I often notice I’m getting better at Python/Java as well.

You also touch on a key point when you say incredibly frustrating. For me, if I get to that point, I just switch to something parallel. I really used to hate Java to no end but after python it doesn’t bother me anymore. Stepping away temporarily doesn’t mean quitting.

Anyways, this is all stream-of-consciousness stuff, hope there’s something of use in there.

Thank you for sharing your experience. It’s been suggested I learn Python and then javaScript, I don’t really understand what python does and I’m afraid my brain can’t take in that much weird stuff at once. Maybe I will try anyways. I need to learn JavaScript and node and vue and this other weird framework stuff? for work because apparently you can’t use HTML and CSS anymore it’s all done with JavaScript…which makes no sense but nothing does anymore.

Think of python as a sandbox type of code. What it “can” do is many things. What learning its structure gives people is a strong sense of how things fit together. Java was the first language I learned over a decade ago, but when I learned python the reason I liked it is because it feels closer to how humans think. So in that sense it feels like a “bridge” language to lower level languages (like C).

Now, when I have to do something in Java, C#, or Javascript, I often think, how would I do that in python?? And then just translate it back.

1 Like

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.