From 4971a298399bc13ab37ead6239a8b6491242bfc6 Mon Sep 17 00:00:00 2001 From: Jake Gerber Date: Sat, 10 Oct 2020 13:37:40 -0700 Subject: [PATCH] Added isOdd function. --- Maths/isOdd.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Maths/isOdd.js diff --git a/Maths/isOdd.js b/Maths/isOdd.js new file mode 100644 index 000000000..22acc8deb --- /dev/null +++ b/Maths/isOdd.js @@ -0,0 +1,21 @@ +//Returns true if a number is odd, returns false if a number is even, and returns null if the number is a decimal. +function isOdd (num) { + + if (num < 0) + { + num *= -1 + } + + if (Math.floor(num) !== num) + { + console.error('Decimal Value') + return null + } + + if (num % 2 === 1) + { + return true + } + + return false +} \ No newline at end of file