Here are the JavaScript source codes for the given problems:
COMPARISON
<script>
var x = 50;
var y = 68;
var z = (x < y);
alert(z);
</script>
LOGICAL
<script>
var x = 50;
var y = 68;
var z = (x == y && y == x);
alert(z);
</script>
CONDITIONAL
<script>
var answer = prompt("What is the first calculating device? Abacus or Comptometer?", "");
var result = (answer == "Abacus") ? "Congratulation!" : "Try Again";
alert(
JavaScript Comparison and Logical Operators Explained
1. JAVASCRIPT
COMPARISON AND
LOGICAL OPERATORS
BENJAMIN B. ESGUERRA MEMORIAL NATIONAL HIGH
SCHOOL
2. JavaScript Comparison and Logical
Operators
Comparison and Logical operators are
used to test for true or false.
Comparison Operators are used in
logical statements to determine equality
or difference between variables or values.
Logical Operators are used to determine
the logic between variables or values.
3. COMPARISON OPERATORS
Given that x=5, the table below explains the comparison operators.
Operator Description Comparing Returns
x==8 FALSE
== is equal to x==5 TRUE
x==="5" FALSE
is exactly equal to (value and type) x===5 TRUE
!= is not equal x!=8 TRUE
x!=="5" TRUE
!== is not equal (neither value or type) x!==5 FALSE
> is greater than x>8 FALSE
< is less than x<8 TRUE
>= is greater than or equal to x>=8 FALSE
<= is less than or equal to x<=8 TRUE
6. LOGICAL OPERATORS
Given that x=6 and y=3 the table below explains the logical
operators.
Operator Description Comparing Returns
&&
(ampersand) and (x<10 && y>1) TRUE
|| or (x==5||y==5) FALSE
! not !(x==y) TRUE
7. <script>
var x= 10
var y= 2
var z= (x>y && y<x)
confirm("Is "+x+" greater than "+y+" ?, and
"+y+" is less than "+x+" ?");
alert(""+z+"");
</script>
</body>
</html>
8. CONDITIONAL OPERATOR
JavaScript also contains a conditional operator that assigns a
value to a variable based on some conditions.
SYNTAX:
variable name= (condition)? value1:value2
Example:
If the variable age is value below 18, the value of the
variable voteable will be “Too young, otherwise the
value of votaable will be “Old enough”
var age= 18
var voteable= (age<18)? “Too young”:”Old
enough”
9. <html>
<body>
<script>
var x= prompt("Who created the JavaScript? "," ");
var y= “Brendan Eich"
var z= (x==y)?"Correct": "Wrong";
alert(""+z+"");
document.write("Correct Answer: "+y+"");
</script>
</body>
</html>
10. Assign/Seatwork
Create the JavaScript source code
COMPARISON
50 is less than 68
LOGICAL
50 is equal to 68 and 68 is equal to 50
CONDITIONAL
What is the first calculating device? Abacus
or Comptometer?
Condition: Congratulation! And Try Again