Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

What is wrong with this function?

Define a function called quarter which has a parameter called number. This function returns a value equal to one quarter of the parameter. (i.e. number / 4;) Call the function inside the if statement's condition (and put in a parameter value!) such that "The statement is true" is printed to the console. ?

var quarter = function (number) { console.log(number/4) }

if (quarter() % 3 === 0 ) { console.log("The statement is true"); } else { console.log("The statement is false"); }

2 Answers

Michael Hulet
Michael Hulet
47,911 Points

First of all, you're declaring the function wrong. It's declared as function name(parameters){//Code}. After that, I don't think you're supposed to call console.log() inside of the function, but just have the function return the proper value, instead. Tell me if this works:

function quarter(number){
  return number/4;
}
if(quarter(8) % 2 === 0){
  console.log("The statement is true");
}
else{
  console.log("The statement is false");
}

yes that worked. Thank you very much.