[go: up one dir, main page]

0% found this document useful (0 votes)
8 views5 pages

LAS Q3 WEEK 2 For Uploading

This document is a learning activity sheet for Grade Level students at Guiuan National High School, focusing on HTML and JavaScript, specifically on IF, ELSE IF, and NESTED IF statements. It provides definitions, syntax, and examples of these programming concepts, along with sample problems for practice. The document aims to enhance students' understanding of conditional statements in programming.

Uploaded by

Maraiah Yves
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)
8 views5 pages

LAS Q3 WEEK 2 For Uploading

This document is a learning activity sheet for Grade Level students at Guiuan National High School, focusing on HTML and JavaScript, specifically on IF, ELSE IF, and NESTED IF statements. It provides definitions, syntax, and examples of these programming concepts, along with sample problems for practice. The document aims to enhance students' understanding of conditional statements in programming.

Uploaded by

Maraiah Yves
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/ 5

Department of Education

Region VIII
Division of Eastern Samar
GUIUAN NATIONAL HIGH SCHOOL
Guiuan, Eastern Samar

COMPUTER PROGRAMMING

Name of Learner: __________


Grade Level: ______________
Section: __________________
Date: ____________________

LEARNING ACTIVITY SHEET


(Quarter 3 - Week 2)
HTML/JAVASCRIPT
IF, ELSE IF THEN & NESTED IF STATEMENT

INTRODUCTION

In this learning activity, we will be dealing with IF, ELSE IF THEN.

What is an IF statement?
➢ The IF/ELSE statement executes a block of code if a specified condition is
true. If the condition returns false, another block of codes can be executed.

Example:

if(your age is above or equal to 18){


-display “You’re of legal age.”
}

In this particular example, if the value of age is above or equal to 18, then
Javascript displays “You’re of legal age.”.

Note: You can have multiple IF statement to execute a particular problem.

What are the parts of the Javascript?

• CONDITION STATEMENT
-specifies the condition in which the IF statement checks to see
whether it’s true or not.
1
• BLOCK OF CODES
-to be executed when the condition is true or false.

What is the syntax of an IF statement?

if(condition){
*codes to execute if the condition is true
}

Ex:
var age = 15;

if(age<18){
console.log(“You are a minor.”);
}

What is an Else If statement?


-else if is used to specify a new condition to test, if the condition is false.

Ex:
if(is the food delicious?){
*codes to be executed if the condition is true
}
else if(is food homecooked?){
*codes to be executed if the condition is true
}else{
*codes to be executed if the condition is false.
}

What is Nested IF statement?


-it is an IF statement inside an IF statement.

Ex:
if(do you to school?){ 1st statement/argument
if(do you go to Guiuan National High School?){ 2nd argument
*codes to be executed if the condition is true
}

2
else{ part of the 2nd argument
*codes to execute if condition is false.
}
}
else{ part of the 1st argument
*codes to be executed if condition is false
}

In this nested IF statement, the only time that the 2nd argument will get checked is
if the 1st argument returns true. If the 1st argument returns true, the else part of the
1st argument will get executed.

Note: You can place several IF statement inside an IF statement.

Sample Problem 1:

Create a code that will say “You passed” if the inputted grade is 75 and above
and “You failed” if the inputted grade is 74 below.

Codes for problem 1:

var grade = 75; let’s just initialize grade with the value of 75

if(grade>=75){
console.log(“You Passed”);
}
else{
console.log(“You failed”);
}

Sample problem 2:

Create a Nested statement that if your grade is below 75, it will say “You failed”.
If it’s above 75, check if it’s 75-85, 86-94, 95-100. If it’s 75-85, display “with
honors”. If it’s 86-94, display “with high honors”. If it’s 95-100, display “with
highest honor”. If it’s above 100, display “Grade above limit”.

3
Codes for Problem 2:

Solution1:

var grade = 90; let’s initialize value to 90. You can change it if you want
if(grade>=75){
if(grade>=75 && grade<=85){
console.log(“with honors!”);
}else if(grade>=86 && grade<=95){
console.log(“with high honors!”);
}else if(grade>=96 && grade<=100){
console.log(“with highest honors!”);
}else{
console.log(“Grade above limit!”);
}
}else{
console.log(“You failed!”);
}

Solution 2:

var grade = 90; let’s initialize value to 90. You can change it if you want

if(grade>=75){
if(grade>=95){
console.log(“with highest honor”);
}
else if(grade>=85){
console.log(“with high honor”);
}
else if(grade>=75){
console.log(“with honor”);
}
}
else{
console.log(“you failed”);
}

4
Sample Problem 3:

Catalina is a business woman. Create a code that will keep track of her daily
business expenses, monthly expenses, daily income and her monthly income.
Also, display if she is gaining from her business or taking a loss. If monthly
income is the same as monthly_expenses, display “Business is not gaining nor
losing money”.

Codes for Problem 3:

var daily_expenses = 600; let’s initialize value to 600


var daily_income = 600; let’s initialize value to 600
var monthly_expenses = daily_expenses * 30;
var monthly_income = daily_income * 30;

if(monthly_income==monthly_expenses){
console.log(“Business is not gaining nor losing money.”);
}
else if(monthly_income>monthly_expenses){
console.log(“Catalina is gaining from her business.”);
}
else{
console.log(“Catalina is taking a loss in her business.”);
}

You might also like