|
| 1 | +### Comparison Operators Exercises |
| 2 | + |
| 3 | +***Note: __ = blank** |
| 4 | + |
| 5 | + |
| 6 | +**1. Fill in the blank with the correct comparison operator to alert true, when x is greater than y.** |
| 7 | + |
| 8 | + x = 10; |
| 9 | + y = 5; |
| 10 | + alert(x __ y); |
| 11 | + |
| 12 | +<details> |
| 13 | +<summary>SHOW ANSWER</summary> |
| 14 | +> |
| 15 | +</details> |
| 16 | +
|
| 17 | + |
| 18 | +**2. Fill in the blank with the correct comparison operator to alert true, when x is equal to y.** |
| 19 | + |
| 20 | + x = 10; |
| 21 | + y = 10; |
| 22 | + alert(x __ y); |
| 23 | + |
| 24 | +<details> |
| 25 | +<summary>SHOW ANSWER</summary> |
| 26 | +== OR === |
| 27 | +</details> |
| 28 | + |
| 29 | + |
| 30 | +**3. Fill in the blank with the correct comparison operator to alert true, when x is NOT equal to y.** |
| 31 | + |
| 32 | + x = 10; |
| 33 | + y = 5; |
| 34 | + alert(x __ y); |
| 35 | + |
| 36 | +<details> |
| 37 | +<summary>SHOW ANSWER</summary> |
| 38 | +!= OR !== |
| 39 | +</details> |
| 40 | + |
| 41 | + |
| 42 | +**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".** |
| 43 | + |
| 44 | + var age = n; |
| 45 | + var votingStatus = (age __ 18) __ "Too young" __ "Old enough"; |
| 46 | + alert(votingStatus); |
| 47 | + |
| 48 | +<details> |
| 49 | +<summary>SHOW ANSWER</summary> |
| 50 | +< ? : |
| 51 | +</details> |
| 52 | + |
| 53 | + |
| 54 | +**5. Will the output for this statement be true or false?** |
| 55 | + |
| 56 | + console.log(1 == 1); |
| 57 | + |
| 58 | +<details> |
| 59 | +<summary>SHOW ANSWER</summary> |
| 60 | +true |
| 61 | +</details> |
| 62 | + |
| 63 | + |
| 64 | +**6. Will the output for this statement be true or false?** |
| 65 | + |
| 66 | + console.log(1 == "1"); |
| 67 | + |
| 68 | +<details> |
| 69 | +<summary>SHOW ANSWER</summary> |
| 70 | +true |
| 71 | +</details> |
| 72 | + |
| 73 | + |
| 74 | +**7. Will the output for this statement be true or false?** |
| 75 | + |
| 76 | + console.log(1 === 1); |
| 77 | + |
| 78 | +<details> |
| 79 | +<summary>SHOW ANSWER</summary> |
| 80 | +true |
| 81 | +</details> |
| 82 | + |
| 83 | + |
| 84 | +**8. Will the output for this statement be true or false?** |
| 85 | + |
| 86 | + console.log(1 === "1"); |
| 87 | + |
| 88 | +<details> |
| 89 | +<summary>SHOW ANSWER</summary> |
| 90 | +false |
| 91 | +</details> |
| 92 | + |
| 93 | + |
| 94 | +**9. Will the output for this statement be true or false?** |
| 95 | + |
| 96 | + console.log(1 != "1"); |
| 97 | + |
| 98 | +<details> |
| 99 | +<summary>SHOW ANSWER</summary> |
| 100 | +false |
| 101 | +</details> |
| 102 | + |
| 103 | + |
| 104 | +**10. Will the output for this statement be true or false?** |
| 105 | + |
| 106 | + console.log(1 !== "1"); |
| 107 | + |
| 108 | +<details> |
| 109 | +<summary>SHOW ANSWER</summary> |
| 110 | +true |
| 111 | +</details> |
| 112 | + |
| 113 | + |
| 114 | +**11. What will the value of the variable color be after the following statement is executed?** |
| 115 | + |
| 116 | + var color = 5 < 10 ? "red" : "blue"; |
| 117 | + |
| 118 | +<details> |
| 119 | +<summary>SHOW ANSWER</summary> |
| 120 | +"red" |
| 121 | +</details> |
0 commit comments