From 242936c0467839d0345304a5109bb494349c4997 Mon Sep 17 00:00:00 2001 From: Don Date: Thu, 23 Jun 2022 15:32:25 -0400 Subject: [PATCH] Completed leapYears and tempConversion exercises --- 06_leapYears/leapYears.js | 13 +++++++++++-- 06_leapYears/leapYears.spec.js | 10 +++++----- 07_tempConversion/tempConversion.js | 8 ++++---- 07_tempConversion/tempConversion.spec.js | 10 +++++----- 4 files changed, 25 insertions(+), 16 deletions(-) diff --git a/06_leapYears/leapYears.js b/06_leapYears/leapYears.js index 681eeef..dee5d99 100644 --- a/06_leapYears/leapYears.js +++ b/06_leapYears/leapYears.js @@ -1,5 +1,14 @@ -const leapYears = function() { - +const leapYears = function(year) { + if (year % 4 == 0) { + if (year % 100 == 0) { + if (year % 400 == 0) { + return true + } + return false + } + return true + } + return false }; // Do not edit below this line diff --git a/06_leapYears/leapYears.spec.js b/06_leapYears/leapYears.spec.js index 6fdaba9..2cd4110 100644 --- a/06_leapYears/leapYears.spec.js +++ b/06_leapYears/leapYears.spec.js @@ -4,19 +4,19 @@ describe('leapYears', () => { test('works with non century years', () => { expect(leapYears(1996)).toBe(true); }); - test.skip('works with non century years', () => { + test('works with non century years', () => { expect(leapYears(1997)).toBe(false); }); - test.skip('works with ridiculously futuristic non century years', () => { + test('works with ridiculously futuristic non century years', () => { expect(leapYears(34992)).toBe(true); }); - test.skip('works with century years', () => { + test('works with century years', () => { expect(leapYears(1900)).toBe(false); }); - test.skip('works with century years', () => { + test('works with century years', () => { expect(leapYears(1600)).toBe(true); }); - test.skip('works with century years', () => { + test('works with century years', () => { expect(leapYears(700)).toBe(false); }); }); diff --git a/07_tempConversion/tempConversion.js b/07_tempConversion/tempConversion.js index 6ef3e85..601711f 100644 --- a/07_tempConversion/tempConversion.js +++ b/07_tempConversion/tempConversion.js @@ -1,9 +1,9 @@ -const ftoc = function() { - +const ftoc = function(fTemp) { + return Number(((fTemp - 32) * (5 / 9)).toFixed(1)) }; -const ctof = function() { - +const ctof = function(cTemp) { + return Number(((cTemp * (9 / 5)) + 32).toFixed(1)) }; // 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); }); });