JavaScript Any help with the code will be appreciated I kept getting false for both args.

dr3apap

New Coder
Nov 14, 2019
5
0
1
function isRoundedNumberEven (decimal) {
if (decimal % 2 === 0 ) {
console.log("true")
} else {
console.log('false')
}
return decimal
}
/* Do not modify code below this line */
console.log(isRoundedNumberEven(2.2), '<-- should be true');
console.log(isRoundedNumberEven(2.8), '<-- should be false')
 

joe

Coder
Aug 21, 2019
39
20
8
What exactly is the function going to do?
Inside the if condition, you're checking whether the number is even or not; but your not rounding the given number before doing that. May be that's causing the problem.
 

dr3apap

New Coder
Nov 14, 2019
5
0
1
Even when I round it, its's still not output the result. Can you help me check it out yourself it suppose to console log the output on the codes cus I was suppose to modify the ruction to output the result.
 

Malcolm

Administrator
Administrator
Verified
Jan 2, 2018
1,103
303
95
Canada
codeforum.org
function isRoundedNumberEven (decimal) {
if (decimal % 2 === 0 ) {
console.log("true")
} else {
console.log('false')
}
return decimal
}
/* Do not modify code below this line */
console.log(isRoundedNumberEven(2.2), '<-- should be true');
console.log(isRoundedNumberEven(2.8), '<-- should be false')
Hi,

Please add more information regarding what this is and what your trying to do. And make sure to include your code in bbcode tags, https://codeforum.org/help/bb-codes/
 

swift

New Coder
Nov 11, 2019
9
3
3
There are 2 things that you'll need to deal with in your function.
  1. You're performing a modulus operation (% 2) on the input (which may not be an integer). Before you do that you should make sure that you are rounding the value as the function name implies it should do
  2. It currently returns the input argument as it's output, so if you give it 2.2, it will give you 2.2 in return. Instead you should change it from the console.log('true' / 'false') to returning the appropriate value as a result of your if/else check.
Hope that makes sense :thumbsup: