Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • 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.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • 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

Coder
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')
 
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.
 
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.
 
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/
 
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:
 
Back
Top Bottom