* feat(tools): add seed/solution restore script * chore(curriculum): remove empty sections' markers * chore(curriculum): add seed + solution to Chinese * chore: remove old formatter * fix: update getChallenges parse translated challenges separately, without reference to the source * chore(curriculum): add dashedName to English * chore(curriculum): add dashedName to Chinese * refactor: remove unused challenge property 'name' * fix: relax dashedName requirement * fix: stray tag Remove stray `pre` tag from challenge file. Signed-off-by: nhcarrigan <nhcarrigan@gmail.com> Co-authored-by: nhcarrigan <nhcarrigan@gmail.com>
2.1 KiB
id, title, challengeType, videoUrl, forumTopicId, dashedName
id | title | challengeType | videoUrl | forumTopicId | dashedName |
---|---|---|---|---|---|
56533eb9ac21ba0edf2244d0 | Comparison with the Equality Operator | 1 | https://scrimba.com/c/cKyVMAL | 16784 | comparison-with-the-equality-operator |
--description--
There are many comparison operators in JavaScript. All of these operators return a boolean true
or false
value.
The most basic operator is the equality operator ==
. The equality operator compares two values and returns true
if they're equivalent or false
if they are not. Note that equality is different from assignment (=
), which assigns the value on the right of the operator to a variable on the left.
function equalityTest(myVal) {
if (myVal == 10) {
return "Equal";
}
return "Not Equal";
}
If myVal
is equal to 10
, the equality operator returns true
, so the code in the curly braces will execute, and the function will return "Equal"
. Otherwise, the function will return "Not Equal"
. In order for JavaScript to compare two different data types (for example, numbers
and strings
), it must convert one type to another. This is known as "Type Coercion". Once it does, however, it can compare terms as follows:
1 == 1 // true
1 == 2 // false
1 == '1' // true
"3" == 3 // true
--instructions--
Add the equality operator to the indicated line so that the function will return "Equal" when val
is equivalent to 12
.
--hints--
testEqual(10)
should return "Not Equal"
assert(testEqual(10) === 'Not Equal');
testEqual(12)
should return "Equal"
assert(testEqual(12) === 'Equal');
testEqual("12")
should return "Equal"
assert(testEqual('12') === 'Equal');
You should use the ==
operator
assert(code.match(/==/g) && !code.match(/===/g));
--seed--
--seed-contents--
// Setup
function testEqual(val) {
if (val) { // Change this line
return "Equal";
}
return "Not Equal";
}
testEqual(10);
--solutions--
function testEqual(val) {
if (val == 12) {
return "Equal";
}
return "Not Equal";
}