0% found this document useful (0 votes)
16 views15 pages

Teens - Teaching Test EN

The document covers programming concepts including For Loops, Conditionals, and Functions, primarily in JavaScript. It explains the structure and purpose of a For Loop, how conditionals dictate program execution based on specific criteria, and defines functions as reusable code sequences. Each section includes examples and coding practices to reinforce understanding of these concepts.
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)
16 views15 pages

Teens - Teaching Test EN

The document covers programming concepts including For Loops, Conditionals, and Functions, primarily in JavaScript. It explains the structure and purpose of a For Loop, how conditionals dictate program execution based on specific criteria, and defines functions as reusable code sequences. Each section includes examples and coding practices to reinforce understanding of these concepts.
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/ 15

Meeting 4

FOR LOOP

• Learn about for loop

1
Timedoor Coding Academy
Meeting 4

4
PROBLEM SOLVING
PRACTICE

Now we are going to learn about another new loop called For Loop.

For Loop
Repetition of a process where we already know the number
of times it’ll repeat or commonly used for repetition with a
certain pattern.

Look at the use of for loop below!

Counter Starting Value Stop Value Step Value


variable that holds the starting the ending value the number that
the number of value of the which determines is added each
loops counter variable when the loop time the loop is
stops. executed.

From the code above, how many times will the command be
repeated? Check out the explanation below first!

2
Timedoor Coding Academy
Meeting 4 - Problem Solving Practice and For Loop
FOR LOOP

What is the meaning of counter?

Counter is a variable. Imagine that a counter as a


container. For example, it can be imagined like an

What is the meaning of From 1?

From 1 means the starting value is 1.


It means that, at the beginning the aquarium
only

What is the meaning of To 3?

To 3 means the ending value is 3. It means that


the last time aquarium can be added fish again
when the number is equal to 3.

Then, what is the meaning of Counted by 1?

This means that the value will be counted by 1 for each loop. The number of fish w
keep increasing by 1 as long as the number of fish in the aquarium has not reached

Number of fish ≤ 3? Number of fish ≤ 3 ? Number of fish ≤ 3 ? Number of fish ≤ 3 ?

+1 +1 +1
Yes Yes Yes No
To determine the loop, check the number of times +1 is
executed.

3
Timedoor Coding Academy
Meeting 4 - Problem Solving Practice and For Loop
FOR LOOP

For Loop in JavaScript

This time we will use for loop on JavaScript!

Pay attention to the Foor Loop syntax in Javascript!

Keyword for Condition

for (i=0; i<5; i++){

//commands to repeat
}
Repeated Commands

Same as For Loops in block coding, the condition For Loop


consists of 3 parts. .

Starting Stop Step


Value Value Value

4
Timedoor Coding Academy
Meeting 4 - Problem Solving Practice and For Loop
CODING PRACTICE

v
Timedoor Coding Academy
i
Timedoor Coding Academy
Meeting 6
7

WHAT IF ?

• Learn about conditional

5
Timedoor Coding Academy
Meeting

6 CONDITIONAL

Let’s learn about verbal logic!

CASE 1

If test score is more than 70, Arjuna can enter the Intermediate
class.
This means:
What is the condition for Arjuna to enter the Intermediate Class?
What will happen if the score is less than 70?

Condition for something to happen is called as Conditional.


In coding, this code is used as a term/condition for a program to
be executed.

Conditional
Term/condition for a program to be executed.

6
Timedoor Coding Academy
Meeting 6- What If
CONDITIONAL 1 CONDITION

Previously, we learned what a conditional is. Conditional with 1


condition means the program will be executedif the condition/term
is fulfilled

CASE 2
If Chito is hungry, Chito will eat.
If Chito is sleepy, Chito will sleep.
If Chito will do an exam, Chito will study.

This means: :
If Chito feels hungry, what will he do?
What is the condition for Chito to sleep?
What is the condition for Chito to study?

Do you understand the example above? Then how can you


implement those examples into block coding?
Please check the codes below!

7
Timedoor Coding Academy
Meeting 6- What If
CONDITIONAL 1 CONDITION

Now try to understand the code below!


The code below will congratulate the student in different ways based
on his/her test score.

What is the condition that must be fulfilled to receive the remark


“Excellent”?

What will the program say if the socre obtained is 78?

What will the program say if the socre obtained is 50?

8
Timedoor Coding Academy
Meeting 6- What If
NESTED CONDITIONAL

9
Timedoor Coding Academy
x
Timedoor Coding Academy
Meeting 18

FUNCTION

• Learn about function

10
Timedoor Coding Academy
Meeting

18 WHAT IS FUNCTION?

WHAT IS FUNCTION?
Observe the story below!

During lunch break, Bintang wanted to buy fried rice. He said “Hi,
I want to buy some fried rice” to the cook. Then what did the cook
do?

1. Prepare materials
2. Put the pan on the stove
3. Turn on the stove
4. Heat the oil
5. Pour the rice and other seasonings into the pan
6. Stir until cooked
7. Turn off the stove and serve the fried rice

Whenever Bintang wants to buy fried rice,


Does Bintang have to give the command steps 1-7 to the
cook?

11
Timedoor Coding Academy
Meeting 18- Function, Real or Fake?
WHAT IS FUNCTION?

Every time Bintang gives the command “Buy fried rice”. The cook
will do steps 1-7. This means that the commands of buying fried
rice already represents the steps 1 to 7. In coding it can be called
as a function.

Function
Commands that represent sequences of code to execute a
specific task and can be used over and over again.

Define a Function
Function must be created before they can be called.
Notice how to create function in JavaScript.

keyword function name

function functionName(){
//function body

} function body goes


inside curly bracket

Calling a Function
To run the code in the function body, we must call the function name.
function name

functionName();

Don’t forget to put open and close parentheses and a semicolon


after the function name.
12
Timedoor Coding Academy

You might also like