From 773994f8b0895efa8e4f6c476f8e14c56240eab5 Mon Sep 17 00:00:00 2001 From: Othamae Date: Fri, 30 Jun 2023 11:36:01 +0200 Subject: [PATCH] Reto #26 - javascript --- .../javascript/othamae.js | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 Retos/Reto #26 - TESTING [Media]/javascript/othamae.js diff --git a/Retos/Reto #26 - TESTING [Media]/javascript/othamae.js b/Retos/Reto #26 - TESTING [Media]/javascript/othamae.js new file mode 100644 index 0000000000..450a276a61 --- /dev/null +++ b/Retos/Reto #26 - TESTING [Media]/javascript/othamae.js @@ -0,0 +1,39 @@ +/* + * Crea tres test sobre el reto 12: "Viernes 13". + * - Puedes copiar una solución ya creada por otro usuario en + * el lenguaje que estés utilizando. + * - Debes emplear un mecanismo de ejecución de test que posea + * el lenguaje de programación que hayas seleccionado. + * - Los tres test deben de funcionar y comprobar + * diferentes situaciones (a tu elección). + */ + +const assert = require('assert') + +// Function to test +const isFriday13th = (month, year) => { + const date = new Date(year, month - 1, 13) + return date.getDay() === 5 +} + +// Examples +console.log(isFriday13th(8, 2021)) // true +console.log(isFriday13th(10, 2021)) // false +console.log(isFriday13th(5, 2022)) // true +console.log(isFriday13th(1, 2023)) // true +console.log(isFriday13th(6, 2022)) // false +console.log(isFriday13th(10, 2023)) // true + +// Test 1: Check a month with Fridat 13th +assert.strictEqual(isFriday13th(8, 2021), true) + +// Test 2: Check a month that doesnt have Friday 13th +assert.strictEqual(isFriday13th(10, 2021), false) + +// Test 3: Ckeck that the response is not null +const result = isFriday13th(1, 2023) +assert.ok(result !== null) +assert.notStrictEqual(result, null) +assert.notStrictEqual(result, undefined) + +console.log("Tests passed") \ No newline at end of file