* chore(learn): audit basic algorithm scripting * chore(learn): audit basic data structures * chore(learn): audit basic javascript * chore(learn): audit debugging * chore(learn): audit es6 * chore(learn): audit functional programming * chore(learn): audit intermidate algorithms * chore(learn): audit js projects * chore(learn): audit object oriented programming * chore(learn): audit regex * fix(learn): remove stray . * fix(learn): string to code * fix(learn): missed some * fix(learn): clarify strings Based on Randy's feedback, clarifies string instances where quotes were removed in favour of back ticks. * fix: apply suggestions - thanks Randy! :) Co-authored-by: Randell Dawson <5313213+RandellDawson@users.noreply.github.com> * fix: non-suggestion comments * chore(learn): remove comments from codes Removes the comments from the description and instruction code blocks to ensure that all relevant information is translatable. * fix: Apply suggestions from code review Co-authored-by: Shaun Hamilton <51722130+ShaunSHamilton@users.noreply.github.com> * fix: revert crowdin fix * Update curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-algorithm-scripting/mutations.md Co-authored-by: Randell Dawson <5313213+RandellDawson@users.noreply.github.com> * fix: Apply suggestions from code review Co-authored-by: Shaun Hamilton <51722130+ShaunSHamilton@users.noreply.github.com> * Update curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/use-destructuring-assignment-to-assign-variables-from-arrays.md Co-authored-by: Shaun Hamilton <51722130+ShaunSHamilton@users.noreply.github.com> * fix: Apply suggestions from code review Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> Co-authored-by: Shaun Hamilton <51722130+ShaunSHamilton@users.noreply.github.com> * chore: change voice * fix: Christopher Nolan * fix: expressions would evaluate * fix: will -> would * Update curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/add-methods-after-inheritance.md Co-authored-by: Randell Dawson <5313213+RandellDawson@users.noreply.github.com> * fix: to work to push * Update curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/iterate-with-javascript-for-loops.md Co-authored-by: Shaun Hamilton <51722130+ShaunSHamilton@users.noreply.github.com> * Update curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/add-methods-after-inheritance.md Co-authored-by: Randell Dawson <5313213+RandellDawson@users.noreply.github.com> Co-authored-by: Randell Dawson <5313213+RandellDawson@users.noreply.github.com> Co-authored-by: Shaun Hamilton <51722130+ShaunSHamilton@users.noreply.github.com> Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
2.2 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
1 == 2
1 == '1'
"3" == 3
In order, these expressions would evaluate to true
, false
, true
, and true
.
--instructions--
Add the equality operator to the indicated line so that the function will return the string Equal
when val
is equivalent to 12
.
--hints--
testEqual(10)
should return the string Not Equal
assert(testEqual(10) === 'Not Equal');
testEqual(12)
should return the string Equal
assert(testEqual(12) === 'Equal');
testEqual("12")
should return the string 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";
}