8000 tempConversion done · unconnect/javascript-exercises@84072a9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 84072a9

Browse files
committed
tempConversion done
1 parent 5bc4b4b commit 84072a9

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

07_tempConversion/tempConversion.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
1-
const ftoc = function() {
1+
// Rounding numbers by representing them in exponential notation
2+
// https://www.jacklmoore.com/notes/rounding-in-javascript/#:~:text=rounding%20in%20JavaScript.-,Rounding%20Errors,round()%20.
3+
function round(value, decimals) {
4+
return Number(Math.round(value + 'e' + decimals) + 'e-' + decimals);
5+
}
26

7+
const ftoc = function(ftemp) {
8+
const ctemp = (ftemp - 32) * 5 / 9;
9+
return round(ctemp, 1);
310
};
411

5-
const ctof = function() {
6-
12+
const ctof = function(ctemp) {
13+
const ftemp = ctemp * 9 / 5 + 32;
14+
return round(ftemp, 1);
715
};
816

917
// Do not edit below this line

07_tempConversion/tempConversion.spec.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,22 @@ describe('ftoc', () => {
44
test('works', () => {
55
expect(ftoc(32)).toEqual(0);
66
});
7-
test.skip('rounds to 1 decimal', () => {
7+
test('rounds to 1 decimal', () => {
88
expect(ftoc(100)).toEqual(37.8);
99
});
10-
test.skip('works with negatives', () => {
10+
test('works with negatives', () => {
1111
expect(ftoc(-100)).toEqual(-73.3);
1212
});
1313
});
1414

1515
describe('ctof', () => {
16-
test.skip('works', () => {
16+
test('works', () => {
1717
expect(ctof(0)).toEqual(32);
1818
});
19-
test.skip('rounds to 1 decimal', () => {
19+
test('rounds to 1 decimal', () => {
2020
expect(ctof(73.2)).toEqual(163.8);
2121
});
22-
test.skip('works with negatives', () => {
22+
test('works with negatives', () => {
2323
expect(ctof(-10)).toEqual(14);
2424
});
2525
});

0 commit comments

Comments
 (0)
0