WDMD 170 – UW Stevens Point 1 WDMD 170 Internet Languages eLesson: Decision Making with Control Structures and Statements (non-audio version) © Dr. David.

Slides:



Advertisements
Similar presentations
Decision Structures - If / Else If / Else. Decisions Often we need to make decisions based on information that we receive. Often we need to make decisions.
Advertisements

Control Structures.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2 Introduction to XHTML Programming the World Wide Web Fourth edition.
Advanced SQL Topics Edward Wu.
Copyright © 2003 Pearson Education, Inc. Slide 1.
Copyright © 2003 Pearson Education, Inc. Slide 1 Computer Systems Organization & Architecture Chapters 8-12 John D. Carpinelli.
Chapter 1 The Study of Body Function Image PowerPoint
1 Copyright © 2013 Elsevier Inc. All rights reserved. Chapter 1 Embedded Computing.
1 Copyright © 2013 Elsevier Inc. All rights reserved. Appendix 01.
1 Copyright © 2013 Elsevier Inc. All rights reserved. Chapter 3 CPUs.
© 2010 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Chapter 5: Repetition and Loop Statements Problem Solving & Program.
XP New Perspectives on Microsoft Office Word 2003 Tutorial 6 1 Microsoft Office Word 2003 Tutorial 6 – Creating Form Letters and Mailing Labels.
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
FACTORING ax2 + bx + c Think “unfoil” Work down, Show all steps.
Year 6 mental test 10 second questions
REVIEW: Arthropod ID. 1. Name the subphylum. 2. Name the subphylum. 3. Name the order.
Variables Conditionals Boolean Expressions Conditional Statements How a program produces different results based on varying circumstances if, else if,
4.1 © 2004 Pearson Education, Inc. Exam Managing and Maintaining a Microsoft® Windows® Server 2003 Environment Lesson 4: Organizing a Disk for Data.
Modern Programming Languages, 2nd ed.
Microsoft Access.
1 University of Utah – School of Computing Computer Science 1021 "Thinking Like a Computer"
1 What is JavaScript? JavaScript was designed to add interactivity to HTML pages JavaScript is a scripting language A scripting language is a lightweight.
VOORBLAD.
The if-else Statements
Factor P 16 8(8-5ab) 4(d² + 4) 3rs(2r – s) 15cd(1 + 2cd) 8(4a² + 3b²)
Computer Programming 12 Mr. Jean April 2 nd, 2014.
© 2012 National Heart Foundation of Australia. Slide 2.
Lecture 7: Software Design (Part II)
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 4 Loops.
Understanding Generalist Practice, 5e, Kirst-Ashman/Hull
Project 6: Working with If Statements Essentials for Design JavaScript Level One Michael Brooks.
1 of 31 Images from Africa. 2 of 31 My little Haitian friend Antoine (1985)
Macromedia Dreamweaver MX 2004 – Design Professional Dreamweaver GETTING STARTED WITH.
Pasewark & Pasewark Microsoft Office XP: Introductory Course 1 INTRODUCTORY MICROSOFT WORD Lesson 8 – Increasing Efficiency Using Word.
Programming Fundamentals 1 st lecture. ELTE 2/ Content  Steps of solving problems – steps of writing a computer.
Chapter 9 Interactive Multimedia Authoring with Flash Introduction to Programming 1.
Types of selection structures
Decision Making EE2372 Software Design I Dr. Gerardo Rosiles.
©Brooks/Cole, 2001 Chapter 12 Derived Types-- Enumerated, Structure and Union.
1 Chapter 3:Operators and Expressions| SCP1103 Programming Technique C | Jumail, FSKSM, UTM, 2006 | Last Updated: July 2006 Slide 1 Operators and Expressions.
Intracellular Compartments and Transport
PSSA Preparation.
Chapter 11 Describing Process Specifications and Structured Decisions
Essential Cell Biology
Presentation 7: JavaScript continued Control structures and functions Fundamentals of Web-Centric Development.
CMPT 100 : INTRODUCTION TO COMPUTING TUTORIAL #5 : JAVASCRIPT 2 GUESSING GAME By Wendy Sharpe 1.
2 nd Semester Selection Statement Computer and Programming (204111)
Chapter 3 Flow of Control Copyright © 2010 Pearson Addison-Wesley. All rights reserved.
L6:CSC © Dr. Basheer M. Nasef Lecture #6 By Dr. Basheer M. Nasef.
WDMD 170 – UW Stevens Point 1 WDMD 170 Internet Languages eLesson: Using Data Types (No Audio Component) © Dr. David C. Gibbs
CIS101 Introduction to Computing Week 11. Agenda Your questions Copy and Paste Assignment Practice Test JavaScript: Functions and Selection Lesson 06,
Tutorial 4 Decision Making with Control Structures and Statements Section A - Decision Making JavaScript Tutorial 4 -Decision Making with Control.
WDMD 170 – UW Stevens Point 1 WDMD 170 Internet Languages eLesson: Working with Forms in JavaScript (NON-audio version) © Dr. David C. Gibbs
WDMD 170 – UW Stevens Point 1 WDMD 170 Internet Languages eLesson: Data Types and Operators (NON Audio Version) © Dr. David C. Gibbs
Chapter 4: Decision Making with Control Structures and Statements JavaScript - Introductory.
COMPUTER PROGRAMMING. Control Structures A program is usually not limited to a linear sequence of instructions. During its process it may repeat code.
CPS120: Introduction to Computer Science Decision Making in Programs.
JavaScript Tutorial 1 - Introduction to JavaScript WDMD 170 – UW Stevens Point 1 WDMD 170 Internet Languages eLesson: Introduction to JavaScript (NON.
WDMD 170 – UW Stevens Point 1 WDMD 170 Internet Languages eLesson: Decision Making with Control Structures and Statements (non-audio version) © Dr. David.
WDMD 170 – UW Stevens Point 1 WDMD 170 Internet Languages eLesson: Variables, Functions and Events (there is an audio component to this eLesson) © Dr.
JavaScript Tutorial 1 - Introduction to JavaScript WDMD 170 – UW Stevens Point 1 WDMD 170 Internet Languages eLesson: Introduction to JavaScript – A First.
Chapter 15 JavaScript: Part III The Web Warrior Guide to Web Design Technologies.
WDMD 170 – UW Stevens Point 1 WDMD 170 Internet Languages eLesson: Working with Windows (No audio component) © Dr. David C. Gibbs
WDMD 170 – UW Stevens Point 1 WDMD 170 Internet Languages eLesson: Variables, Functions and Events (NON-Audio version) © Dr. David C. Gibbs WDMD.
CPS120: Introduction to Computer Science Decision Making in Programs.
Presentation transcript:

WDMD 170 – UW Stevens Point 1 WDMD 170 Internet Languages eLesson: Decision Making with Control Structures and Statements (non-audio version) © Dr. David C. Gibbs

WDMD 170 – UW Stevens Point 2 Tutorial 4 Decision Making with Control Structures and Statements Section A - Decision Making

WDMD 170 – UW Stevens Point 3 Tutorial 4A Topics Section A - Decision Making –if statements –if…else statements –nested if statements –switch statements

WDMD 170 – UW Stevens Point 4 Previewing the CartoonQuiz.html file Follow the directions on p. 172 of Gosselin Here is the file: CartoonQuiz.htmlCartoonQuiz.html View the source code, taking note of the for and if statements. (This file is also in your student files in the Tutorial04 folder.)

WDMD 170 – UW Stevens Point 5 Decision Making Process of determining the order in which statements execute in a program – the “flow of control” Decision-Making Structures –Special type of JavaScript statements used for making decisions Single alternative: if Double alternative: if-else Multiple alternatives: extended (or nested) if-else, switch

WDMD 170 – UW Stevens Point 6 if Statements Single-alternative “if” Used to execute specific programming code if the evaluation of a conditional expression returns a value of true –“Do this or don’t do this” Syntax (3 primary parts) statement1; if (conditional_expression) statement2; statement3;

WDMD 170 – UW Stevens Point 7 conditional expression true statement 2 false statement 3 statement 1 if flow diagram

WDMD 170 – UW Stevens Point 8 if Statements (2) Operation –If the conditional expression is true, the statements are executed –Control then continues to subsequent code “Command block” –Multiple statements contained within a set of braces (require curly braces)

WDMD 170 – UW Stevens Point 9 Evaluating an “if” statement to true

WDMD 170 – UW Stevens Point 10 Evaluating an “if” statement to false

WDMD 170 – UW Stevens Point 11 “if” statement with command block

WDMD 170 – UW Stevens Point 12 if Statements Conditional Expression –Can consist of: Comparison operators Logical operators Combination of the two –Must resolve to Boolean value

WDMD 170 – UW Stevens Point 13 Comparison and logical operators with the if statement (p. 176) (source file)source file var exampleVar1 = 5; if (exampleVar1 != 3)// not equal document.writeln("This line prints."); if (exampleVar1 > 3)// greater than document.writeln("This line prints."); if (exampleVar1 < 3)// less than document.writeln("This line does not print."); if (exampleVar1 >= 3)// greater than or equal document.writeln("This line prints."); if (exampleVar1 <= 3)// less than or equal document.writeln("This line does not print."); var exampleVar2 = false; if (exampleVar1 > 3 && exampleVar2 == true) // logical and document.writeln("This line does not print."); if (exampleVar1 == 5 || exampleVar2 == true) // logical or document.writeln("This line prints."); if (!exampleVar2) // logical 'not' document.writeln("This line prints."); Example 1 Example 2 Example 3 Example 4 Example 5 Example 6 Example 7 Example 8

WDMD 170 – UW Stevens Point 14 Valid JS Expressions Stated Expression Valid JavaScript Expression x < y <= z ((x < y) && (y <= z)) x, y, and z are greater than 0 ((x > 0) && (y > 0) && (z > 0)) x is equal to neither y nor z ((x != y) && (x != z)) x is equal to y and z ((x = = y) && (x = = z))

WDMD 170 – UW Stevens Point 15 Refer to the instructions on pages (Gosselin). [Note that you are going to create a simplified version of the CartoonQuiz you previewed earlier. Create the file CartoonQuiz1.htm and save it in your Tutorial04 folder. Preview and Test your.htm file. eTask 1

WDMD 170 – UW Stevens Point 16 if…else Statements Used to execute one set of code if the evaluation of a conditional expression returns a value of true, otherwise executes another set of code –“Do this or do something else” Syntax priorStatement; if (conditional_expression) if statement; else statement; subsequentStatement;

WDMD 170 – UW Stevens Point 17 conditional expression true if statement false subsequent statement prior statement else statement if-else diagram

WDMD 170 – UW Stevens Point 18 if…else statement

WDMD 170 – UW Stevens Point 19 Refer to the instructions on page 183 (Gosselin). [You will make use of the if-else statement.] Create the file CartoonQuiz2.htm and save it in your Tutorial04 folder. Preview the.htm file. eTask 2

WDMD 170 – UW Stevens Point Nested and Extended if statements (Accepted definitions from computer science – slightly different than Gosselin’s usage) nested if: a selection statement used within another selection statement. extended if: nested selection where additional if..else statements are used in the else option.

WDMD 170 – UW Stevens Point 21 Nested if and if…else Statements Nested statements –Statements contained within other statements (note how indentation makes the usage much clearer) Syntax if (conditional_expression) { statement(s); if (conditional_expression) { statement(s); } } else { statement(s); }

WDMD 170 – UW Stevens Point extended if Statements An extended if statement is an if statement where the else clause is itself another if statement. if (expression1) statement1; else if (expression2) statement2; else if (expression3) statement3; else statement4;

WDMD 170 – UW Stevens Point extended if Statements, cont’d. The extended if statement is often formatted as follows: if (expression1) statement1; else if (expression2) statement2; else if (expression3) statement3; else statement4; Notice how easy it is to read. “Default” behavior results from omitting an expression from the final else clause.

WDMD 170 – UW Stevens Point 24 Greeting program with nested if statements

WDMD 170 – UW Stevens Point 25 Greeting program with nested if statements – proper formatting

WDMD 170 – UW Stevens Point 26 Refer to the instructions on page (Gosselin). [You will make use of extended if-else statements.] Create the file CartoonQuiz3.htm and save it in your Tutorial04 folder. Preview the.htm file. eTask 3

WDMD 170 – UW Stevens Point 27 switch Statements Controls program flow by executing a specific set of statements, depending on the value of an expression Syntax switch (expression) { case label1: statement(s); break; case label2: statement(s); break; default: statement(s); } Note that there is no break statement following the last case label – the default label. WHY?

WDMD 170 – UW Stevens Point 28 switch Statements cont’d. Case labels –Identify specific code segments –Can use a variety of data types as case labels Break statement –Used to exit switch statements Default label –Contains statements that execute when the condition expression doesn’t match any of the case labels

WDMD 170 – UW Stevens Point 29 Examples of case labels

WDMD 170 – UW Stevens Point 30 Greeting program with a switch statement

WDMD 170 – UW Stevens Point 31 Refer to the instructions on page 192 (Gosselin). [You will make use of the switch statement.] Create the file CartoonQuiz4.htm and save it in your Tutorial04 folder. Preview the.htm file. eTask 4

WDMD 170 – UW Stevens Point 32 Assignment Complete exercises #3,4,6-9,12 on pages (Gosselin, Tutorial 04A). Post your solutions to your Tutorial04 folder CISSRV3 server. Provide a link to exercise 12 in a post to your eReview discussion group. Describe any difficulties and ask any questions you might have in completing exercise 12. You may also post any questions (and the exercise file) to the eReview group – for discussion purposes.

WDMD 170 – UW Stevens Point 33 End of eLesson Jump to the Beginning of this eLesson WDMD 170 Course Schedule D2L Courseware Site