Skip to content

Commit 4971a29

Browse files
authored
Added isOdd function.
1 parent d23cd4a commit 4971a29

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

Maths/isOdd.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//Returns true if a number is odd, returns false if a number is even, and returns null if the number is a decimal.
2+
function isOdd (num) {
3+
4+
if (num < 0)
5+
{
6+
num *= -1
7+
}
8+
9+
if (Math.floor(num) !== num)
10+
{
11+
console.error('Decimal Value')
12+
return null
13+
}
14+
15+
if (num % 2 === 1)
16+
{
17+
return true
18+
}
19+
20+
return false
21+
}

0 commit comments

Comments
 (0)