I’m working on a Codecademy exercise:
Remember the functions isOdd and isEven from Exercise 3.4?
We’d like you to code them here again! But this time, the aim is to define one function in terms of the other using the ! symbol.
Define isOdd, and then define isEven in terms of isOdd.
I tried a few different ways that I though would work,
like console.log(!isOdd(1));
and
(n !% 2 ===),
none of them are right.
Here is the code that I have:
var isOdd = function (n)
{
if (n % 2 ===0)
{
return false;
} else {
return true;
}
};
var isEven =function (n)
{
if (n % 2 === 0)
{
return true;
} else {
return false;
}
};
console.log(isOdd(1));
console.log(isOdd(2));
console.log(isOdd(999));
It’s straightforward: