How can I call a function in javascripf where find number even or odd.
Asked
Active
Viewed 299 times
-5
-
3Show some effort! Google your question and you'll find this (first result): http://stackoverflow.com/questions/6211613/testing-whether-a-value-is-odd-or-even – Antti29 Feb 07 '16 at 16:07
-
2First, write the function. Second, call it. – David Feb 07 '16 at 16:08
2 Answers
0
Ever hear of modulus?
if (n % 2 == 0)
{
// I'm even
}
else
{
// I'm odd
}

Michael Benjamin
- 346,931
- 104
- 581
- 701

EDD
- 2,070
- 1
- 10
- 23
0
function myFunction(n) {
if(n % 2 == 0)
console.log("n is even");
else
console.log("n is odd"); // The function returns the odd/even no.
}
then call function as
myfunction(k);
where k is the number as input
If it helps..please mark my answer

Zaki Mustafa
- 147
- 1
- 11