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


#1

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;}
};
nap(tired,bored);


#2

What is the error you are receiving?


#3

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.


#4

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?


#5

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....


#6

https://www.codecademy.com/courses/javascript-beginner-en-qDwp0/2/3?curriculum_id=506324b3a7dffd00020bf661

looks like the question was not set out right.


#7

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.