From 968c20eba75bd41c27fc61c90c11ef41661caddf Mon Sep 17 00:00:00 2001 From: Japoncio3k <49957327+Japoncio3k@users.noreply.github.com> Date: Fri, 9 Oct 2020 14:41:58 -0300 Subject: [PATCH] Added isDivisble.js (#437) * Added isDivisble.js * isDivisible.js is now on StandardJS style * isDivisible now have examples --- Maths/isDivisible.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 Maths/isDivisible.js diff --git a/Maths/isDivisible.js b/Maths/isDivisible.js new file mode 100644 index 000000000..072957e92 --- /dev/null +++ b/Maths/isDivisible.js @@ -0,0 +1,15 @@ +// Checks if a number is divisible by another number. + +const isDivisible = (num1, num2) => { + if (isNaN(num1) || isNaN(num2) || num1 == null || num2 == null) { + return 'All parameters have to be numbers' + } + if (num2 === 0) { + return 'Not possible to divide by zero' + } + return num1 % num2 === 0 +} + +console.log(isDivisible(10, 5)) // returns true +console.log(isDivisible(123498175, 5)) // returns true +console.log(isDivisible(99, 5)) // returns false