Write a JavaScript function that takes an integer as an argument and returns "Even" if it's an even number or "Odd" if it's an odd number.
function checkEvenOrOdd(number) {
if (number % 2 === 0) {
return "Even";
} else {
return "Odd";
}
}
-
Modify the function to handle non-integer inputs gracefully. Return an error message if the input is not an integer. (Hint: Use
typeof
operator). [+5 extra credit points] -
Implement the function without using conditional statements (if-else). (Hint: Use
Math.floor
andMath.abs
functions). [+5 extra credit points] -
Extend the function to check if the input is a positive or negative even or odd number. (Hint: Use
Math.sign
function). [+5 extra credit points]
-
Kindly go to
src
directory and editsolution.js
file. -
Replace the
commented code
with your solution.