Write two functions that convert temperatures from Fahrenheit to Celsius, and vice versa
This commit is contained in:
parent
4204350a10
commit
f40d0db982
|
@ -1,7 +1,14 @@
|
||||||
const convertToCelsius = function() {
|
const convertToCelsius = function(input) {
|
||||||
};
|
let celcius = `${(input - 32) * 5/9}`;
|
||||||
|
let newNumber = parseFloat(Number(celcius).toFixed(1));
|
||||||
|
return newNumber;
|
||||||
|
}
|
||||||
|
|
||||||
const convertToFahrenheit = function() {
|
|
||||||
|
const convertToFahrenheit = function(input) {
|
||||||
|
let fahrenheit = `${(input * 9/5) + 32}`;
|
||||||
|
let newFahrenheit = parseFloat(Number(fahrenheit).toFixed(1));
|
||||||
|
return newFahrenheit;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Do not edit below this line
|
// Do not edit below this line
|
||||||
|
|
|
@ -4,22 +4,22 @@ describe('convertToCelsius', () => {
|
||||||
test('works', () => {
|
test('works', () => {
|
||||||
expect(convertToCelsius(32)).toEqual(0);
|
expect(convertToCelsius(32)).toEqual(0);
|
||||||
});
|
});
|
||||||
test.skip('rounds to 1 decimal', () => {
|
test('rounds to 1 decimal', () => {
|
||||||
expect(convertToCelsius(100)).toEqual(37.8);
|
expect(convertToCelsius(100)).toEqual(37.8);
|
||||||
});
|
});
|
||||||
test.skip('works with negatives', () => {
|
test('works with negatives', () => {
|
||||||
expect(convertToCelsius(-100)).toEqual(-73.3);
|
expect(convertToCelsius(-100)).toEqual(-73.3);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('convertToFahrenheit', () => {
|
describe('convertToFahrenheit', () => {
|
||||||
test.skip('works', () => {
|
test('works', () => {
|
||||||
expect(convertToFahrenheit(0)).toEqual(32);
|
expect(convertToFahrenheit(0)).toEqual(32);
|
||||||
});
|
});
|
||||||
test.skip('rounds to 1 decimal', () => {
|
test('rounds to 1 decimal', () => {
|
||||||
expect(convertToFahrenheit(73.2)).toEqual(163.8);
|
expect(convertToFahrenheit(73.2)).toEqual(163.8);
|
||||||
});
|
});
|
||||||
test.skip('works with negatives', () => {
|
test('works with negatives', () => {
|
||||||
expect(convertToFahrenheit(-10)).toEqual(14);
|
expect(convertToFahrenheit(-10)).toEqual(14);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue