Kelvin Weather. Math.Floor not working and type erorrs

// Variables

const kelvin = 0;

const celsius = kelvin - 273;

// Kelvin to Celsius

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

// Fahrenheit to Celsius

fahrenheit == Math.floor(fahrenheit)

//fahrenheit round

console.log(The temperature is ${fahrenheit} degrees Fahrenheit.)

console.log(kelvin);

console.log(celsius);

console.log(fahrenheit);

//Checks

const newton = celsius * (33/100);

newton == Math.floor(newton);

console.log(newton)

log

Output-only Terminal

Output:

The temperature is -459.40000000000003 degrees Fahrenheit. 0 -273 -459.40000000000003 -90.09
Version 1
// Variables

const kelvin = 0;

const celsius = kelvin - 273;

// Kelvin to Celsius

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

// Fahrenheit to Celsius

fahrenheit = Math.floor(fahrenheit)

//fahrenheit round

console.log(The temperature is ${fahrenheit} degrees Fahrenheit.)

console.log(kelvin);

console.log(celsius);

console.log(fahrenheit);

//Checks

const newton = celsius * (33/100);

newton = Math.floor(newton);

console.log(newton)

log
/home/ccuser/workspace/learn-javascript-intro-kelvin-weather/app.js:9
fahrenheit = Math.floor(fahrenheit)
^

TypeError: Assignment to constant variable.
at Object. (/home/ccuser/workspace/learn-javascript-intro-kelvin-weather/app.js:9:12)
at Module._compile (module.js:571:32)
at Object.Module._extensions…js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at Module.runMain (module.js:605:10)
at run (bootstrap_node.js:427:7)
at startup (bootstrap_node.js:151:9)
at bootstrap_node.js:542:3

Version 2

I do not understand what is going on I checked it was the answer in the hints

If you declare a variable using const, then you can’t change the value assigned to that variable.

You had const fahrenheit = celsius * (9 / 5) + 32
so you can’t assign a number to fahrenheit afterward using fahrenheit =

If you change the const to let, then you can change the value of the variable.

Alternatively, you could do
const fahrenheit = Math.floor( celsius * (9 / 5) + 32 );
to get everything done on the same line, so that you don’t need to change the value of fahrenheit.

2 Likes