So this is what I have
Lesson
Use the strict equality operator in the if
statement so the function will return “Equal” when val
is strictly equal to 7
and this is what I understood from it:
so then the line should be onto the if one
then it must be equal to 7
Then we have the example code which is
3 === 3 // true
so then here it should be 7 === 7 so it is equal
then we have the last one which i also changed from 10 to 7
yet when i submite the following it doesn’t pass
why?
// Setup
function testStrict(val) {
if (7 === 7) { // true
return "Equal";
}
return "Not Equal";
}
// Change this value to test
testStrict(7);
link to the lesson
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/comparison-with-the-strict-equality-operator
Your function will always return "Equal"
regardless of the value of val
. You need to test val
in the if condition.
1 Like
Could you explain it to me a bit simpler? I find it hard to understand :3
This is what i got so far from it
You said that the *1function which is in this case could refere to the function testStrict(val)? our the ===? Would Equal regardless of the value of the val. I assume the value means the number? since it gives a true with the number but not the string in th lesson.
Then you said i needed to test the val in the if condition? what excatly does that mean? which of the val do are you refering to?
1A function is a block of code that will do a assigned task given to it.
Your function is hardcoded to check if 7 === 7
. Of course this is true, so no matter what value you pass to the function, it will always return "Equal"
.
Which it shouldn’t. It should only return "Equal"
if val
's value is 7
.
Thank you a bunch for the explanation :3 For futher revereces
if (val === 7) { // Change this line
will do the trick since 7 is now set to val which result in true