Issues with 8. Functions, return and if/else


#1

Hello! I am a fairly new coder and I am having issues with 8. Functions, return, if/else. Long story short, I took a long break off of javascript and lost a lot of learning, and now coming back it's difficult to do even the simplest stuff, so pardon me if my mistake is really obvious, and I'm just really oblivious.

Here is a link to the problem I am stuck on: https://www.codecademy.com/en/courses/javascript-beginner-en-6LzGd/1/3?curriculum_id=506324b3a7dffd00020bf661


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

Thank You!


#2

On the last line with return, what is being returned? Check the instructions again to see what the function should return.

You missed the open parentheses before quarter here. The instructions also ask that the number returned by the quarter function must be divisible by 3 and have no remainder. Currently, you are checking to divide a number by 5. Choose any number to input to the quarter function that is divisible by 3 and leaves no remainder.


#3

Thank you for your help!


#4

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

Oops, try again. Hmm, it looks like your quarter function doesn't return -25 for -100.


#5

Hello @maryemhassan
It is always best to start a topic for your own questions. Do you have a question? The code you've posted looks identical to the first in this discussion.


#6

"We want quarter(some number) that when divided by 3 has remainder 0."

Why are you putting 20 and 5 when the original is talking about
if (quarter() % 3 === 0 ) {
console.log("The statement is true");
} else {
console.log("The statement is false");
}


#8

I am in the same situation as samikan, except that I stuck with the original instructions that johneubank08 points out.

// Define quarter here.
var quarter = function(number)
{
var val = number / 4
return val
};
{
if (quarter(27) % 3 === 0)
console.log("The statement is true");
} else {
console.log("The statement is false");
}

I am a beginner and am often puzzled by the instructions. Here a function is called and the value it returns must equal ) when divided by 3. What is supposed to be returned "quarter" or "val?" Neither makes a difference. I keep getting a syntax error.

I don't really understand why I need a return, except that the instructions call for it.

Am I just screwing up with a brace or a semi-colon?


#9

Nevermind. I ended up fixing it. I am just not sure how. I am often confused by what the instructions are really asking me to do.


#10

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.