12 why is that


#1

if my code is:

var tired = true
var bored = false
var nap = function() {
if (tired || bored) {
return true
} else {
return false
}

};
=> everything is ok

but if it is

var tired = true
var bored = false
var nap = function(tired, bored) {
if (tired || bored) {
return true
} else {
return false
}

};
=> it says:"Oops, try again.
It looks like your function doesn't return true when tired is true and bored is false.
"


#2

Your function doesn't take input (Or it isn't supposed to) it relys on previously specified variables. On the inside, tired and bored will both have null value, because they are supposedly input function variables.


#4

var tired = false;
var bored = true;

var nap = function() {
// Add your if/else statement here!
if (tired || bored) {
return true;
} else if (!(bored) || tired) {
return false;
} else {
return true;
}
};


#5

As @cadecodes said, by using parameters you declare new local variables which have except their name nothing in common with the global ones outside of the function. The way they get their values is by the function call but as the test function doesn't expect inputs its probably just nap() which leads to the inner tired and bored to stay undefined. Which leads to a false output when a true one is expected.

Hope this helps.

@javasolver29955
Please read the questions and try to give appropriated answers. Posting code without any explanation isn't considered very helpful and if the author already has working code but asks a question beyond this it is even worse. Thank you for trying to help but please do it in a way that explains what the problem is and what you did or what the OP can do to fix it. Thank you.


#6

Both are helpful. I can deduce what I did wrong by looking at the right code; I don't always need someone to hold my hand.

Sure it would've been nice if he wrote some guideline but you refusing to give the correct answer is just as infuriating. Working backwards is a thing, y'know?


#7

"And I don't like this kind of help. Mainly because it has several problems.

First of all it is not clear that it is visible to the author what
the actual problem is and what solved it so that the bug doesn't occur a
second time or at least can be identified. Also keep in mind that the
exercises are rather short so in the end the codes will all look pretty
similar and an "I almost got it" might not always be correct. Also the question "typo or lack of understanding" is an individual one. The second thing is it is not save that it is really a solution and free of bugs. That is of course a risk every comment has but for just code comments it might be worse. Third, all the exercises
should be possible if you stick to the instruction both technically and
from understanding. And if this is not the case it is better to point
that out than give advices on how to "cheat" on the exercise. And as it is about learning your basically cheating on yourself because this may lead to a lack of understanding of the basic concepts.

There might even be more reasons but I guess these are enough for
now. I'd rather recommend using code snippets showing the problem and
giving hints about the underlying concept. Or at least mark the problems
in your solution.

Also there is no reason for posting a solution if there is already a solution
in this post, this just makes the topic unnecessarily long and
confusing. At this point I'd like to cut this to not make the post any
longer. "

A quote I wrote elsewhere. So I'd rather say do not post solution buts hints and if you do at least give some information with it so that one can see where the problem is and how to solve it.