I'm getting errors in tutorials for More on Control Flow in JS. Below is the code:


Can anyone please help what is wrong here?

// Declare your variables here!
var tired = true;
var bored = false;
var nap = function(j1,j2) {
// Add your if/else statement here!
if (j1 || j2)//j1 && j2 or !j1
{return true;}
else {return false;}


What is the error you are receiving?


Oops, try again. It looks like your function doesn't return false when tired and bored are both false.

And does not let me move further.


Hmm, I can't see anything wrong with your code. It should definitely be returning false if they're both set to false. Can you paste the link to the exact exercise?


Ok so the problem here is that you set tired to true in your first line:

Well then you called in in the function so j1 = tired:

Because of that this statement says If j1 OR j2 is true, then return true... in this case tired is true so your resulting function will return true:

To solve this just declare tired as false in the beggining....



looks like the question was not set out right.


Okay I see what the problem is - the SCT isn't expecting nap() to have any parameters so tests the function without any when checking if your code is correct. I believe this is why the initial code template is set up like this:

// Declare your variables here!

var nap = function() {
  // Add your if/else statement here!

The solution would be to change the function so it doesn't use parameters.