Pavan Kumar
Pavan Kumar

Reputation: 11

issue in conversion from Fahrenheit to Celsius

below code to get equivalent Fahrenheit of 12 degree Celsius throws an error saying missing ;

var celsius = 12;
var fahrenheit = celsius x 1.8 + 32;
console.log(fahrenheit);

Upvotes: 0

Views: 332

Answers (2)

Todd
Todd

Reputation: 5454

x isn't a valid operator; though I can see how it could be overlooked.

fixed:

var celsius = 12;
var fahrenheit = celsius * 1.8 + 32; // x not an operator
console.log(fahrenheit);

as a function:

const fahrenheitFromCelsius = (deg) => deg * 1/8 + 32;

Upvotes: 0

Dust_In_The_Wind
Dust_In_The_Wind

Reputation: 3692

Multiplication is done with * in JavaScript.

var celsius = 12;
var fahrenheit = celsius * 1.8 + 32;
console.log(fahrenheit)

Upvotes: 3

Related Questions