From 07d6d7683f485e1a24f85d5fa929612e240e07aa Mon Sep 17 00:00:00 2001 From: octopusGarden Date: Fri, 4 Nov 2022 15:28:29 -0400 Subject: [PATCH] Replaced toFixed with Math.round --- 07_tempConversion/tempConversion.js | 10 ++++------ 07_tempConversion/tempConversion.spec.js | 10 +++++----- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/07_tempConversion/tempConversion.js b/07_tempConversion/tempConversion.js index 12ede60..a512194 100644 --- a/07_tempConversion/tempConversion.js +++ b/07_tempConversion/tempConversion.js @@ -1,17 +1,15 @@ const ftoc = function(fnum) { //formula to convert f to c - let cnum = (fnum - 32) * 5 % 9; + let cnum = (fnum - 32) * 5 / 9; //round to one decimal - let roundCnum = parseInt(cnum.toFixed(1)); - return roundCnum; + return Math.round(cnum * 10) / 10; }; -const ctof = function() { +const ctof = function(cnum) { //formula to convert c to f let fnum = (cnum * 9/5) + 32; //round to one decimal - let roundFnum = parseInt(fnum.toFixed(0)); - return roundFnum; + return Math.round(fnum * 10) / 10; }; // Do not edit below this line diff --git a/07_tempConversion/tempConversion.spec.js b/07_tempConversion/tempConversion.spec.js index 93679cc..b1b82f2 100644 --- a/07_tempConversion/tempConversion.spec.js +++ b/07_tempConversion/tempConversion.spec.js @@ -4,22 +4,22 @@ describe('ftoc', () => { test('works', () => { expect(ftoc(32)).toEqual(0); }); - test.skip('rounds to 1 decimal', () => { + test('rounds to 1 decimal', () => { expect(ftoc(100)).toEqual(37.8); }); - test.skip('works with negatives', () => { + test('works with negatives', () => { expect(ftoc(-100)).toEqual(-73.3); }); }); describe('ctof', () => { - test.skip('works', () => { + test('works', () => { expect(ctof(0)).toEqual(32); }); - test.skip('rounds to 1 decimal', () => { + test('rounds to 1 decimal', () => { expect(ctof(73.2)).toEqual(163.8); }); - test.skip('works with negatives', () => { + test('works with negatives', () => { expect(ctof(-10)).toEqual(14); }); });