2018-09-30 23:01:58 +01:00
---
id: 599a789b454f2bbd91a3ff4d
title: Practice comparing different values
challengeType: 1
2020-05-21 17:31:25 +02:00
isHidden: false
2019-02-14 12:24:02 -05:00
videoUrl: 'https://scrimba.com/c/cm8PqCa'
2019-08-05 09:17:33 -07:00
forumTopicId: 301174
2018-09-30 23:01:58 +01:00
---
## Description
<section id='description'>
In the last two challenges, we learned about the equality operator (<code>==</code>) and the strict equality operator (<code>===</code>). Let's do a quick review and practice using these operators some more.
If the values being compared are not of the same type, the equality operator will perform a type conversion, and then evaluate the values. However, the strict equality operator will compare both the data type and value as-is, without converting one type to the other.
<strong>Examples</strong>
2019-05-17 06:20:30 -07:00
```js
3 == '3' // returns true because JavaScript performs type conversion from string to number
3 === '3' // returns false because the types are different and type conversion is not performed
```
2018-09-30 23:01:58 +01:00
<strong>Note</strong><br>In JavaScript, you can determine the type of a variable or a value with the <code>typeof</code> operator, as follows:
2019-05-17 06:20:30 -07:00
```js
typeof 3 // returns 'number'
typeof '3' // returns 'string'
```
2018-09-30 23:01:58 +01:00
</section>
## Instructions
<section id='instructions'>
2019-10-27 15:45:37 -01:00
The <code>compareEquality</code> function in the editor compares two values using the equality operator. Modify the function so that it returns "Equal" only when the values are strictly equal.
2018-09-30 23:01:58 +01:00
</section>
## Tests
<section id='tests'>
```yml
2018-10-04 14:37:37 +01:00
tests:
2018-10-20 21:02:47 +03:00
- text: <code>compareEquality(10, "10")</code> should return "Not Equal"
2019-07-13 00:07:53 -07:00
testString: assert(compareEquality(10, "10") === "Not Equal");
2018-10-20 21:02:47 +03:00
- text: <code>compareEquality("20", 20)</code> should return "Not Equal"
2019-07-13 00:07:53 -07:00
testString: assert(compareEquality("20", 20) === "Not Equal");
2018-10-04 14:37:37 +01:00
- text: You should use the <code>===</code> operator
2019-07-13 00:07:53 -07:00
testString: assert(code.match(/===/g));
2018-09-30 23:01:58 +01:00
```
</section>
## Challenge Seed
<section id='challengeSeed'>
<div id='js-seed'>
```js
// Setup
function compareEquality(a, b) {
if (a == b) { // Change this line
return "Equal";
}
return "Not Equal";
}
compareEquality(10, "10");
```
</div>
</section>
## Solution
<section id='solution'>
```js
function compareEquality(a,b) {
if (a === b) {
return "Equal";
}
return "Not Equal";
}
```
</section>