• Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.
    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

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
49
28
18
learnbuildweb.wordpress.com
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.
 

Master Yoda

Administrator
Administrator
Verified
Jan 2, 2018
1,722
432
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
26
18
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: