Learning Javascript From Mr Saem www.mrsaem.com1.

Slides:



Advertisements
Similar presentations
1 Chapter Five Selection and Repetition. 2 Objectives How to make decisions using the if statement How to make decisions using the if-else statement How.
Advertisements

Executes a statement or statements for a number of times – iteration. Syntax for(initialize; test; increment) { // statements to be executed } Initial.
True or false A variable of type char can hold the value 301. ( F )
5-1 Flow of Control Recitation-01/25/2008  CS 180  Department of Computer Science  Purdue University.
Tutorial 12 Working with Arrays, Loops, and Conditional Statements
Iteration This week we will learn how to use iteration in C++ Iteration is the repetition of a statement or block of statements in a program. C++ has three.
Chapter 6 - Repetition. Introduction u Many applications require certain operations to be carried out more than once. Such situations require repetition.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
© 2004 Pearson Addison-Wesley. All rights reserved5-1 Iterations/ Loops The while Statement Other Repetition Statements.
Loops Doing the same thing over and over and over and over and over and over…
* What kind of loop would I use to complete the following: A. Output all of the prime numbers that are less than 100,000 B. Output the Fibonacci sequence.
EGR 2261 Unit 5 Control Structures II: Repetition  Read Malik, Chapter 5.  Homework #5 and Lab #5 due next week.  Quiz next week.
Control Structures Session 03 Mata kuliah: M0874 – Programming II Tahun: 2010.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
ASP.NET Programming with C# and SQL Server First Edition Chapter 3 Using Functions, Methods, and Control Structures.
Chapter 4: Decision Making with Control Structures and Statements JavaScript - Introductory.
CPS120 Introduction to Computer Science Iteration (Looping)
© 2004 Pearson Addison-Wesley. All rights reserved February 20, 2006 ‘do’ and ‘for’ loops ComS 207: Programming I (in Java) Iowa State University, SPRING.
LOGO Conditional Statements & Loops in JavaScript CHAPTER 10 Eastern Mediterranean University School of Computing and Technology Department of Information.
L OO P S While writing a program, there may be a situation when you need to perform some action over and over again. In such situation you would need.
Chapter 3 Functions, Events, and Control Structures JavaScript, Third Edition.
Loops George Mason University. Loop Structure Loop- A structure that allows repeated execution of a block of statements Loop body- A block of statements;
1 Chapter 9. To familiarize you with  Simple PERFORM  How PERFORM statements are used for iteration  Options available with PERFORM 2.
ITERATIVE STATEMENTS. Definition Iterative statements (loops) allow a set of instruction to be executed or performed several until condition are met.
 2000 Deitel & Associates, Inc. All rights reserved. Chapter 10 - JavaScript/JScript: Control Structures II Outline 10.1Introduction 10.2Essentials of.
Chapter 15 JavaScript: Part III The Web Warrior Guide to Web Design Technologies.
CPS120 Introduction to Computer Science Iteration (Looping)
 In computer programming, a loop is a sequence of instruction s that is continually repeated until a certain condition is reached.  PHP Loops :  In.
Think Possibility 1 Iterative Constructs ITERATION / LOOPS C provides three loop structures: the for-loop, the while-loop, and the do-while-loop. Each.
Repetition Statements (Loops). 2 Introduction to Loops We all know that much of the work a computer does is repeated many times. When a program repeats.
Chapter Looping 5. The Increment and Decrement Operators 5.1.
COMP Loop Statements Yi Hong May 21, 2015.
Catie Welsh February 9,  Friday - No Lab! ◦ Bring questions on Project 2  Lab 3 due on Friday 2.
Flow Control in Imperative Languages. Activity 1 What does the word: ‘Imperative’ mean? 5mins …having CONTROL and ORDER!
Dr. Abdullah Almutairi Spring PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. PHP is a widely-used,
Chad’s C++ Tutorial Demo Outline. 1. What is C++? C++ is an object-oriented programming (OOP) language that is viewed by many as the best language for.
Lecture 7 – Repetition (Loop) FTMK, UTeM – Sem /2014.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
Introduction to Programming G50PRO University of Nottingham Unit 6 : Control Flow Statements 2 Paul Tennent
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 2: Control Structures (Selection & Repetition)
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
PHP Condtions and Loops Prepared by Dr. Maher Abuhamdeh.
CHAPTER 4 DECISIONS & LOOPS
>> Introduction to JavaScript
Tutorial 12 Working with Arrays, Loops, and Conditional Statements
JavaScript: Control Statements I
Ch 7: JavaScript Control Statements I.
Expressions and Control Flow in JavaScript
JavaScript: Control Statements.
JavaScript: Control Statements I
Arrays, For loop While loop Do while loop
Outline Altering flow of control Boolean expressions
Chapter 8 JavaScript: Control Statements, Part 2
T. Jumana Abu Shmais – AOU - Riyadh
Iteration: Beyond the Basic PERFORM
© A+ Computer Science - What is a LOOP? © A+ Computer Science -
Algorithms Take a look at the worksheet. What do we already know, and what will we have to learn in this term?
LOOPS BY: LAUREN & ROMEO.
Logical Operations In Matlab.
Selection Statements.
Computer Science Core Concepts
Conditional Statements & Loops in JavaScript
Chapter 2 Programming Basics.
PROGRAM FLOWCHART Iteration Statements.
‘do’ and ‘for’ loops October 1, 2007 ComS 207: Programming I (in Java)
Web Programming and Design
‘do’ and ‘for’ loops October 2, 2006 ComS 207: Programming I (in Java)
Looping and Repetition
Presentation transcript:

Learning Javascript From Mr Saem

2

3

4

HTML CSS JavaScript 5

6

7

8

9

First Script 10

Add Javascript to it 11

Script Position 12

13

Should end with 14

15

16

Not to use In-Line Script 17

CSS at the Top Scripts at the bottom 18

19

20

21

22

23

24

Variables 25

We create variable to hold some data. So variable is a container. That works as a little piece of computer memory. 26

These need to be in the lowercase. The name of the variable is up to us. No spaces are allowed while naming these. These could be letters, Numbers, _ or $ But you cannot start with a number 27

28

29

30

You may split the variables into one line aswell 31

32

33

You may use “ “ or ‘ ’. But do not mix them such as “ ‘ Javascript understands the data type on its own by the way we assign it. It will understand boolean /logic when we define it as true/false 34

We need to ask questions so we shall use IF for that 35

You will always find these in pairs if you have an opening one you will find A closing one as well. Even if it is after many multiple lines. But it needs to be there 36

A All conditions should boil down into TRUE or FALSE TRUE FALSE 37

oth 38 So both are not =

39

40

Not equal to 41

Code Block 42

var amount = 500; if ( amount < 1000 ) { alert ("Its less than 1000"); } 43

Using else 44

45

46

47 = is a command. NOT a polite description We are setting a value We are assigning a value

48 OR

Some operators are considered more important than others eg Particularlay * and / are regarded more important than others. 49

50

IF you are checking values are equal use the == operator 51

52

53 You are telling You are asking Exactly equal

54

55 AND OR

56

57

58

var a=15; alert(++a); 59 What should the output be?

var a=15; alert(a++); 60 What should the output be?

61

62

Loops 63

64

65

var a=1; while (a<10) { alert(a); } 66 Infinite Loop Created While Loop

var a=1; while (a<10) { alert(a); a++; } 67 While Loop (Output)

var a=100; while (a<10) { alert(a); a++; } 68 While Loop (Output).What should it be ?

Do While. The output ? var a=100; do { alert(a); a++; } while (a<10); 69

70

A short hand way 71

72

The for loop 73 OUTPUT

Three Parts of Four Loop 74 VARIABLE DECLARATION - The first part of the loop which initializes the variable at the beginning of the loop to some value. This value is the starting point of the loop. INCREMENT STATEMENT - The increment statement is the third part of the loop. It is the part of the loop that changes the value of the variable created in the variable declaration part of the loop. The increment statement is the part of the loop which will eventually stop the loop from running. CONDITION - The second part of the loop, and it is the part that decides whether the loop will continue running or not. While the condition in the loop is TRUE, it will continue running. Once the condition becomes FALSE, the loop will stop.

The while loop The code within a while loop will execute while the specified condition is true. 75

In the above code, a variable named num is initialized with the value of 0. The condition in the while loop is that while num is less than 25, 5 should be added to num. Once the value of num is greater than 25, the loop will stop executing The while loop

The do-while loop The do-while loop is very similar to the while loop, but it does things in reverse order. The mechanism of the while loop is - while a condition is true, perform a certain action. The mechanism of the do-while loop is - perform a certain action while a condition is true. Furthermore, the code within a do-while loop will always execute at least once, even if the specified condition is false. This is because the code is executed before the condition is tested. 77

Syntax: do{ execute this code; } while (condition); In the above code, a variable named num is initialized with the value of 5. The condition in the do-while loop is that while num is less than 25, 5 should be added to num. Once the value of num is greater than 25, the loop will stop executing The do-while loop

Breaking out of a loop You can completely break out of a loop when it is still running. This is achieved with the break keyword. Once a loop is exited, the first statement right after it will be executed. The break keyword provides an easy way to exit a loop if an error occurs, or if you found what you were looking for 79

In the above example, the for loop is set to iterate 9 times and print the current value of the variable a during each iteration. The if statement within the loop states that when the variable a is equal to 5, break out of the loop Breaking out of a loop

81