hello, I am having some difficulty in solving this particular problem : -
I have searched for ways to go around it but on the part about primitive boolean I don’t understand it.
In particular, what does this exercise require me to do.
hello, I am having some difficulty in solving this particular problem : -
I have searched for ways to go around it but on the part about primitive boolean I don’t understand it.
In particular, what does this exercise require me to do.
It should return true if it’s s boolean.
Boolean is true
and false
.
So if it’s false, it should return true,
And if it’s true it should return true.
When I did this challenge I used an if statement to check if it was a boolean.
If you use ==
it won’t work, use ===
when checking in the if statement.
The reason for this is, because it needs to be only a boolean.
I have tried to use the “strictly” operator and the rest of the code is working.
but the first two cases where it should return true is not working. what am I not doing right.
A fun fact about JavaScript and perhaps other programming languages is that a comparison is a boolean so if did this
const example () => 1 === 1;
console.log(example()) //true;
It returns true
can I see your code?
okay, here it is:-
function booWho(bool) {
if (bool === Boolean) {
return true;
}else{
return false;
}
}
booWho(null);
This is not how you check the type of a variable
I should use the ‘typeof’ method then in this case a variable.
@JeremyLT , @caryaharper and @amejl172 hey guys, this the code I came up with just now:-
function booWho(bool) {
var i = !!(bool);
if (i === bool) {
return true;
}else{
return false;
}
}
booWho(null);
and it worked. yes
Yeah, that will work to. You’re doing a mildly verbose version of checking that a variable is strictly equivalent to itself cast as a boolean. I think the intended solution is to use typeOf
.
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.