Ask coding questions

← Back to all posts
Had a question about this assignment
JamesCrowley (0)

I can't seem to get this if statement to function correctly. What am I doing wrong? Thanks.

Commentshotnewtop
TheDrone7 (545)

You have the function defined properly, all you need to do is to call the function to run the code inside it.
The general method would be

nameOfFunction(valuesFor, Parameters);

In your case, it would be

exercisedFour(someNumberHere);
JamesCrowley (0)

@TheDrone7 Thanks, I tried to do that initially, but I couldn't figure out where to call the function exactly in the code...
would it be after the second to last semicolon?

TheDrone7 (545)

@JamesCrowley you should always call a function after you've finished defining it. For example

function nameOfFunction (parameter){
    // Statements to be executed
} // Definition finishes here

// Call function now
nameOfFunction(value);
JamesCrowley (0)

@TheDrone7 I thought so, but I still can't seem to get it to work based on the syntax they're asking me to use in the assignment. Here is what I'm doing..

function exerciseFour(value){
  let greaterThanFive = false;
  // In this exercise, you will be given a variable, it will be called: value
  // You will also be given a variable named: greaterThanFive
  // Using an 'if' statement check to see if the value is greater than 5. If it is, re-assign greaterThanFive the boolean true.
  if (value > 5){
    let greaterThanFive = true;
  }
  exerciseFour(6);
  // Please write your answer in the line above.
return greaterThanFive;
}
TheDrone7 (545)

@JamesCrowley you're trying to call the function while defining it, that eventually makes it a recursive function but you're still not calling it in the main program. Look closely to what I said in my last comment.

JamesCrowley (0)

@TheDrone7 @ I realize that the call statement is inside of the function itself, which doesn't work, however I have tried it outside and I can't seem to get it to work right. I'm not sure if this works, but here is a link to the oringinal repl.it

https://repl.it/student/submissions/7199927

JamesCrowley (0)

I'm not sure if it is some formatting issue or what, but it won't mark it as correct even if i delete the return statement that they have put in there by default.

TheDrone7 (545)

@JamesCrowley only the student submitting the assignment and the teacher the assignment is submitted to can see that. I'm afraid I'm neither of them so I can't see it.

TheDrone7 (545)

@JamesCrowley ah yes I see the return statement. I forgot about that. Before you complete the assignment, you'll need to understand how functions and return statements work, here's a link to help you catch the basics - http://www.java2s.com/Tutorials/Javascript/Node.js_Tutorial/0100__Node.js_Functions.htm