From 2291cfe884e922a83157ca80e313bc12197130ab Mon Sep 17 00:00:00 2001 From: Davis Raimon Date: Wed, 25 Sep 2019 23:05:06 +0530 Subject: [PATCH] Checking whether a number is Odd. Using modulo function to determine whether the number is odd. --- snippets/isOdd.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 snippets/isOdd.md diff --git a/snippets/isOdd.md b/snippets/isOdd.md new file mode 100644 index 000000000..9471eca71 --- /dev/null +++ b/snippets/isOdd.md @@ -0,0 +1,17 @@ +--- +title: isOdd +tags: math,beginner +--- + +Returns `true` if the given number is odd, `false` otherwise. + +Checks whether a number is odd or even using the modulo (`%`) operator. +Returns `true` if the number is odd, `false` if the number is even. + +```js +const isOdd = num => num % 2 === 1; +``` + +```js +isOdd(3); // true +```