[go: up one dir, main page]

0% found this document useful (0 votes)
7 views25 pages

Boolean and If-Statement

The document discusses data types in JavaScript, specifically focusing on Booleans and if-statements. It explains the definition and application of Booleans, comparison operators, and the structure of if-statements for conditional execution of code. Additionally, it includes practice exercises for implementing these concepts in coding scenarios.

Uploaded by

pvanessa.shs
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views25 pages

Boolean and If-Statement

The document discusses data types in JavaScript, specifically focusing on Booleans and if-statements. It explains the definition and application of Booleans, comparison operators, and the structure of if-statements for conditional execution of code. Additionally, it includes practice exercises for implementing these concepts in coding scenarios.

Uploaded by

pvanessa.shs
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

What were the data types discussed

in our previous lessons?

Numbers and
Strings
Boolean and if-statement in
javascript
Grade 9
Learning target:
•define Booleans and Conditional Statements
•Apply Booleans and Conditional Statements in
JavaScript and use them to store and
manipulate data in their programs.
Let’s think!
How do Boolean values and the 'if' statement
influence the logic and flow of your code, and how
can mastering these concepts enhance your ability to
design efficient and effective algorithms?
What is Boolean?
Boolean is a datatype
that returns either of
two values i.e. true or
false.
Boolean in javascript
In JavaScript, Boolean is used as a
function to get the value of a variable,
object, conditions, expressions, etc. in
terms of true or false.
console.log (4<5);

Let’s practice!
Open SublimeText and create and HTML document with a
filename, boolean.html.
Type this inside the body:
What are you going to do to make the value true?
Let’s practice!

Let’s check if it will


give us a false or
true output.
Syntax rules for booleans
• Type true and false.
• Do not place any character before
and after the words true and false.
• Use typeof code to check the data
type.
Comparison operators
• Equal to ==
• Greater than >
• Lesser than <
• Greater than or equal to >=
• Less than or equal to <=
• Not equal to !=
Let’s practice
• Type this in your HTML document
and check your console.

Why is it true when the one is a number, and the other one is a string?
Double equal sign converts value in the same type. To solve this, you need to use a triple
equal sign so that JavaScript would tell us that the two values are not the same.
Comparison operators
• Equal to ===
• Greater than >
• Lesser than <
• Greater than or equal to >=
• Less than or equal to <=
• Not equal to != =
Order of operations
1. ()
2. * /
3. + -
4. Comparison operators
Let’s practice
1. Type this:
What is an If-Statement?
In JavaScript, an "if statement" is a control
structure used for conditional execution of
code. It allows you to specify a condition,
and if that condition evaluates to true, the
code block associated with the if
statement is executed.
Analogy
Let’s practice

Let’s write a code that


would say ‘hello’ if it
is true. If not true it
would say ‘ goodbye’.
Let’s practice
Let’s write a code for
this scenario:
The legal driving age is
18 and you are 20
years old.
Let’s think!

What to do if there are 2


conditions?
Let’s practice Try changing 20 to 17. What is now the output?

Legal age of driving is 18.


Let’s make a code that
would notify the user
“Almost there.” if he
reaches the age of 16.
What can be improved in this code?

We can use variable


instead of typing the
number 17 over
again.
Let apply variable
Let’s practice!

Answer FA 3.4 posted in the MS Teams


Assignments Tab.
Exit slip

3 Things I learned today…


2 Things I found interesting…
1 Question I still have…
HOA 3.3 variable, Boolean and if-statement
1. Open your practice activity named variables2.html (the click counter).
2. Create a code that would do the following after “show total clicks” button is
clicked:
a. Show an alert message “You must be busy.” if the clicks are equal to and more
that 20.
b. Show an alert message “You’re gonna break the mouse” if the clicks are equal
to or more than 30.
c. Show an alert message “You must be bored.” if the clicks lesser than 5.
3. Submit the following:
Screenshot of your console and code, and a video recording of your browser.

You might also like