Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 121 additions & 0 deletions docs/Exercise/JavaScript_Basics/comparison_operators.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
### Comparison Operators Exercises

***Note: __ = blank**


**1. Fill in the blank with the correct comparison operator to alert true, when x is greater than y.**

x = 10;
y = 5;
alert(x __ y);

<details>
<summary>SHOW ANSWER</summary>
>
</details>


**2. Fill in the blank with the correct comparison operator to alert true, when x is equal to y.**

x = 10;
y = 10;
alert(x __ y);

<details>
<summary>SHOW ANSWER</summary>
== OR ===
</details>


**3. Fill in the blank with the correct comparison operator to alert true, when x is NOT equal to y.**

x = 10;
y = 5;
alert(x __ y);

<details>
<summary>SHOW ANSWER</summary>
!= OR !==
</details>


**4. Fill in the three blanks with the correct conditional (ternary) operators to alert "Too young" if age is less than 18, otherwise alert "Old enough".**

var age = n;
var votingStatus = (age __ 18) __ "Too young" __ "Old enough";
alert(votingStatus);

<details>
<summary>SHOW ANSWER</summary>
< ? :
</details>


**5. Will the output for this statement be true or false?**

console.log(1 == 1);

<details>
<summary>SHOW ANSWER</summary>
true
</details>


**6. Will the output for this statement be true or false?**

console.log(1 == "1");

<details>
<summary>SHOW ANSWER</summary>
true
</details>


**7. Will the output for this statement be true or false?**

console.log(1 === 1);

<details>
<summary>SHOW ANSWER</summary>
true
</details>


**8. Will the output for this statement be true or false?**

console.log(1 === "1");

<details>
<summary>SHOW ANSWER</summary>
false
</details>


**9. Will the output for this statement be true or false?**

console.log(1 != "1");

<details>
<summary>SHOW ANSWER</summary>
false
</details>


**10. Will the output for this statement be true or false?**

console.log(1 !== "1");

<details>
<summary>SHOW ANSWER</summary>
true
</details>


**11. What will the value of the variable color be after the following statement is executed?**

var color = 5 < 10 ? "red" : "blue";

<details>
<summary>SHOW ANSWER</summary>
"red"
</details>