Kelvin weather


#1

Hello i tried to run this and i got the next message:

SyntaxError: Unexpected identifier ‘fahrenheit’

Here is my code, can someone help to me find the mistake, please?

const kelvin = 294; // We will not change the value saved to kelvin.
const celsius = kelvin - 273; // Celsius is similar to Kelvin, the only difference is that Celsius is 273 degrees less than Kelvin.
let fahrenheit = celsius * (9/5) + 32; // Change Celcius to fahrenheit.
fahrenheit = Math.floor(fahrenheit); // Will round the number.
console.log(`The temperature is ${fahrenheit} degrees fahrenheit.`); // String interpoilation to log the temperature in fahrenheit.
const kelvin = prompt('What is the Kelvin temperature today?'); // Generates a pop-up window that asks the user for input, then it will assign their input to a variable.

#2

The last line is meant to replace the first line, in the last step.


#3

Ok i put it like this:

const kelvin = prompt('What is the Kelvin temperature today?'); 
const celsius = kelvin - 273; 
let fahrenheit = celsius * (9/5) + 32; 
fahrenheit = Math.floor(fahrenheit); 
console.log(`The temperature is ${fahrenheit} degrees fahrenheit.`); 

And yet got the same syntax error, is there something wrong?


#4

What does the error message say? (Also, please include a link to the exercise.)


#5

Unexpected identifier ‘fahrenheit’


#6

Try a page refresh then run again.


#7

Ok, and maybe run the program step by step could help, right?


#8

Your code looks fine. It could just be artefacts still in memory. A Refresh will start a new session but will keep your code.


#9

I got it like this and runs perfect:

const kelvin = prompt(‘What is the Kelvin temperature today?’);
const celsius = kelvin -273;
const fahrenheit = celsius * (9/5) +32;
fahrenheit = Math.floor(fahrenheit);
console.log(The temperature is ${fahrenheit} degrees fahrenheit.);

I used only const for variables, while before i was using let for fahrenheit, what could that mean?


#10

It shouldn’t matter. You’re in global scope so technically let should work for all of three. Write what is asked for in the instructions.


#11

That’s what i did, and then i used the hints and even tho it didn’t worked, so i decided to try const instead of let for that sentence, and it just ran perfectly


#12

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