Kelvin Project: Newton not returning proper result

Hi,
Question about first project - Kelvin Weather. Specifically the Kelvin to Newton Conversion.

My code is returning this:
The temperature is 80 degrees Fahrenheit.
The temperature is ${newton} degrees Newton.

Here is code:

//created variable kelvin and set = 293
const kelvin = 300;
//conv of degrees kelvin to degree celsius
const celsius = kelvin - 273;
//converted celsius to faren
let fahrenheit = celsius * (9 / 5) + 32;
fahrenheit = Math.floor(fahrenheit);
// lost at this point - tried to return values... why didn't need to do that - don't know
console.log(`The temperature is ${fahrenheit} degrees Fahrenheit.`);

let newton = celsius * (33 / 100);
newton = Math.floor(newton);
let newton = Math.floor(celsius * (33/100));
console.log('The temperature is ${newton} degrees Newton.');

Can someone point out where I am going wrong? I would really appreciate it.

Thank you! :slightly_smiling_face:

Apologies.
1 - Found solution video.
2 - Saw he pasted code.
3 - Pasted code from initial console.log
4 - Realized string? used little tick marks as opposed to quote marks.
That fixed my problem.
Hope it helps someone else!

1 Like

Hey there, welcome to the forums!

Since this is where you seem to have got lost (according to the comment in your code anyway), whenever you see a string which looks like this:

this is a string, and my name is ${name}

the ${name} bit is an example of string interpolation. The dollar sign and curly braces - ${} - tell JavaScript to grab the value of whatever expression is inside and place that in the string.

So, we can do this:

let yourName = "John Doe";
console.log(`Welcome to JavaScript, ${yourName}!`);
// output : Welcome to JavaScript, John Doe!

but we can also do more interesting things, like this:

let yourName = ""; // please provide a name

console.log(`Welcome to JavaScript, ${yourName ? yourName : "stranger"}!`);
// output if a name is given will include the name.
// output if no name given: Welcome to JavaScript, stranger!

There’s an exercise on interpolation in the Introduction to JavaScript course.

Thanks ThePityCoder! Appreciate you taking the time.

1 Like