Programming games Reprise on credit cards. Operators. Homework: Catch-up. Work on your JavaScript project.

Slides:



Advertisements
Similar presentations
JavaScript I. JavaScript is an object oriented programming language used to add interactivity to web pages. Different from Java, even though bears some.
Advertisements

Programming with App Inventor Computing Institute for K-12 Teachers Summer 2012 Workshop.
COM311H Zheng, School of C&M, UUJ1 Dynamic Web Authoring JavaScript Basics (Array and Function)
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
True or false A variable of type char can hold the value 301. ( F )
25 October Conditionals and Loops. Presentations Brendan: Cyberwarfare Casey: Online shopping (No current event today)
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
10 November JavaScript. Presentation Hints What do YOU think makes a good presentation Some of my suggestions Don’t write full sentences on slides Talk,
Information Technology Center Hany Abdelwahab Computer Specialist.
Introduction to JavaScript for Python Programmers
Chapter 9 Introduction to ActionScript 3.0. Chapter 9 Lessons 1.Understand ActionScript Work with instances of movie clip symbols 3.Use code snippets.
Chapter 8: String Manipulation
JQuery CS 268. What is jQuery? From their web site:
Programming Games Computer science big ideas. Computer Science jargon. Show virtual dog Homework: [Catch up: dice game, credit card or other form.] Plan.
WML II (“Son of WML”) WML WMLScript. WML - A Quick Review Document structure ,... Text and image controls ...,,..., Navigation controls ,,, Events.
JavaScript – Part II Data Types and Operations George Mason University June 3, 2010.
Introduction to Python
Created by, Author Name, School Name—State FLUENCY WITH INFORMATION TECNOLOGY Skills, Concepts, and Capabilities.
Programming Games Basic HTML5 audio example. Catch-up. Work on basic video. Homework: Complete basic video.
Visual Basic Games: Prepare for Hangman
CSS Class 7 Add JavaScript to your page Add event handlers Validate a form Open a new window Hide and show elements Swap images Debug JavaScript.
Creating Web Documents Questions on JavaScript (lecture, text)? Work on JavaScript examples and/or Project III Calculations Homework: experiment, research.
Javascript. Outline Introduction Fundamental of JavaScript Javascript events management DOM and Dynamic HTML (DHTML)
Chapter 3: Data Types and Operators JavaScript - Introductory.
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
MAT Meyer Week 2 Programming VB: ‘basics’ Review & preview: Events, variables, statements, etc. Images, Control arrays, For/Next Assignment: read.
1 Conditions Logical Expressions Selection Control Structures Chapter 5.
Extending HTML CPSC 120 Principles of Computer Science April 9, 2012.
Agenda Exam #1 Review Modulus Conditionals Boolean Algebra Reading: Chapter Homework #5.
DHTML AND JAVASCRIPT Genetic Computer School LESSON 5 INTRODUCTION JAVASCRIPT G H E F.
VB Games: Preparing for Memory Brainstorm controls & events Parallel structures (again), Visibility, LoadPicture, User-defined procedures, Do While/Loop,busy.
JavaScript Syntax and Semantics. Slide 2 Lecture Overview Core JavaScript Syntax (I will not review every nuance of the language)
Logic and Control. 4-2 Decision (selection) structure: if (condition) { statement etc. } Example: if (age == 15) { document.write(“ you are a fifteen”);
Programming games Show shaking screen, quiz show. Calculations Homework: (Finish basic Javascript Projects) Make proposal. Work on project.
ECA 225 Applied Interactive Programming1 ECA 225 Applied Online Programming basics.
XP Tutorial 8 Adding Interactivity with ActionScript.
Programming Logic and Design Fourth Edition, Comprehensive Chapter 8 Arrays.
Creating Web Documents catch-up JavaScript slide show tools redirection.
JavaScript, Fourth Edition
ActionScript: For Loops, While Loops, Concatenation and Arrays MMP 220 Multimedia Programming This material was prepared for students in MMP220 Multimedia.
Digital Image Processing Lecture 6: Introduction to M- function Programming.
Programming games Context of what we are doing. Drawing on canvas. Homework: [Complete coin toss examples.] Do your own drawings. Upload files to website.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Introduction to Python Dr. José M. Reyes Álamo. 2 Three Rules of Programming Rule 1: Think before you program Rule 2: A program is a human-readable set.
Programming Games Logic. Slide show. Range input. Storage. Datatypes. Binary numbers. Homework: Catch up. This includes uploading projects to your server.
Chapter 2 Murach's JavaScript and jQuery, C2© 2012, Mike Murach & Associates, Inc.Slide 1.
Gator Engineering Copyright © 2008 W. W. Norton & Company. All rights reserved. 1 Chapter 3 Formatted Input/Output.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Programming Logic and Design Fifth Edition, Comprehensive Chapter 6 Arrays.
Introduction to Javascript. What is javascript?  The most popular web scripting language in the world  Used to produce rich thin client web applications.
JavaScript Tutorial. What is JavaScript JavaScript is the programming language of HTML and the Web Programming makes computers do what you want them to.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
Programming games Show work on site. Work on slide show. Timed event for bouncing ball. Homework: [Finish slide show and upload to site.] Acquire a short.
C++ LANGUAGE MULTIPLE CHOICE QUESTION
Programming Web Pages with JavaScript
CHAPTER 10 JAVA SCRIPT.
Introduction to Scripting
JavaScript Syntax and Semantics
Programming Games Computer science big ideas and Computer Science jargon: review of things we have used in examples. Show virtual dog Homework: [Catch.
T. Jumana Abu Shmais – AOU - Riyadh
Chapter 3: Selection Structures: Making Decisions
Programming Logic and Design Fifth Edition, Comprehensive
JavaScript CS 4640 Programming Languages for Web Applications
Programming games Share your plans for your virtual something.
Chapter 3: Selection Structures: Making Decisions
Web Programming and Design
Web Programming and Design
This is an introduction to JavaScript using the examples found at the CIS17 website. In previous examples I specified language = Javascript, instead of.
JavaScript CS 4640 Programming Languages for Web Applications
Presentation transcript:

Programming games Reprise on credit cards. Operators. Homework: Catch-up. Work on your JavaScript project.

Credit cards (approximation) example of compounding –interest on the interest I could write this in one line, but easier to see in several lines nb1 = old_balance + new_purchases; nb2 = nb1-payment; if (payment<minimum) {nb2=nb2+penalty} nb3 = nb2 + nb2*monthly_interest; old_balance = nb3;

Other applications Shaking window Quiz show Random image on loading

Operators + –does addition if the operands are numbers –concatenation if the operands are strings. So, if you see 11 when you expected to see 2, you will need to change a number into a string * does multiplication / does division - does subtraction

Chocolate shop Example (see on-line, called calculation from forms) Customer enters number of boxes of chocolate and cocoa –uses forms Program calculates total cost and cost with tax. Prices are 'in' the code. (Later example will do proper formatting.)

Computation test function total(f) { var chocolateprice = 2.55; var cocoaprice = 3.15; var chocolatecost = chocolateprice * f.choc.value; var cocoacost = cocoaprice*f.cocoa.value; var taxrate =.06; var totalcost = chocolatecost + cocoacost; var totalpay = totalcost + taxrate*totalcost; var totals = "Total is " + totalcost + " with tax is " + totalpay; f.cost.value=totalcost; f.wtax.value=totalpay; return false; }

Application Form for Chocolate Enter number of goods in each category. Boxes of Chocolate: Boxes of Cocoa: Total:

Modulo operator % Gives remainder after division Clock arithmetic 4 % 12 is 4 13 % 12 is 1 12 % 12 is 0

Use of modulo Slideshow: replace if statement if (ns<= ++sn) { sn = 0; } with sn = (++sn) % ns;

Other operators comparison: these produce values true or false – >= != == logical: produce true or false – && means and (both operands are true) – || means or (one or the other or both are true) – –! Means logical negative others

Equality test Operator is == The = sign by itself does an assignment. if (a==b) { } NOTE: this would not be done if (a==a) but only testing two different variables OR expressions using variables

Looping To do more or less the same thing many times, use a for loop. This makes use of a so-called looping variable, which can be anything. The looping variable is frequently accessed in the body of the loop. for(initialize;condition; increment) { } Often need to have some code outside/prior to the loop to initialize the process

Example: add up elements in array Assume sales is an array. total = 0; for (i=0; i<sales.length; i++) { total += sales[i]; } Or total = 0; for (i=0; i<sales.length; i++) { total = total + sales[i]; }

Example: find max of elements in array Assume sales is an array. best = sales[0]; //first guess for (i=0; i<sales.length; i++) { if (sales[i]>best) { best = sales[i]; } }

Example: want to determine the index of the best best = sales[0]; bi = 0; for (i=0; i<sales.length; i++) { if (sales[i]>best) { bi = i; best = sales[i]; } }

Conditional operator (condition) ? value_if_true : value_if_false canrentcar = (age>25) ? true : false; Say taxrate is.05 unless city is NYC, in which case it is.08 taxrate = (city=="NYC") ?.08 :.05 Can nest conditional operators. Has effect of if this else if this else if this

Conditional operator alternatives if statement. –means you can do more than one thing –Perhaps less error prone switch statement –means you can do more than one thing –combine different possibilities –does require you to think about the break;

Video For each video (in terms of content), you code one element. To make sure it works in different browsers, this single video element has 3 elements. – 5/video.htmlhttp://faculty.purchase.edu/jeanine.meyer/html 5/video.html For video shown only when 'the code' decides to show it, – 5/quizmultiple.htmlhttp://faculty.purchase.edu/jeanine.meyer/html 5/quizmultiple.html

Videos You can use what is demonstrated in the previous examples to choose from among multiple videos. Each needs its own element with elements indicated the set of videos with similar content, each having a unique id. Set up a variable, say v1, v2, using document.getElementById. Start out with both visibility: hidden; in CSS. In the code at the appropriate place, change visibility and use v1.play() or v2.play(), ….

Global and Local variables Writing a var statement outside of any function makes the variable a global variable. It stays around (aka persists). Writing a var statement inside a function OR simply using a variable inside a function that does not have a var statement outside the function, makes the variable local. –What happens in Vegas stays in Vegas.

Detecting arrow keys … sometimes called 'capturing' arrow events Problem: browsers return this information in different ways

Code for arrow keys var keyCode = document.layers ? evt.which : document.all ? evt.keyCode : document.getElementById ? evt.keyCode : 0; This code does not use document.layers or document.all or document.getElementById directly but instead uses their existence to get the correct property. This could be used to get any keyCode. checking browsers

Using arrow keys to move object Strategy: combine code for moving object (in bouncing ball) code for capturing/detecting arrow pressed –detecting a keydown event –figuring out which key

Programming is …. putting techniques together To find out techniques, consult me, book, 'google' to get to OTHER sources –ask me to help with google Work in stages. For example, –my google search produced something buggy –first used alert –then combined with bouncing ball code

String operations Say title is a string (of characters). Use string attributes and methods title = "Programming Games"; title.length gives the number of characters stringname.substr(startingindex, length) –title.substr(1,3) is "rog" –title.substr(12,5) is "Games"

Matching Say you want values such as file names to match if they are partially alike –aviva1.jpg, aviva2.jpg, daniel1.jpg, daniel2.jpg, anne1.jpg, anne2.jpg, etc. –Determine how many letters you need (okay to use extra—2 would work) if (choice1.substr(0,3) == choice2.substr(0,3))

JavaScript & ActionScript ActionScript is the scripting language for Flash. It and JavaScript are based on the same standard in terms of syntax: format, punctuation, grammar. The differences will be –where the code goes –what objects are referenced in the code –ActionScript is compiled: translated all at once. NOTE: the word objects is used in both its normal and its technical meaning.

Finding errors Syntactic errors are analogous to errors in grammar and notation. The code is not legal JavaScript. Examples are leaving out parentheses or brackets or putting operators together. Semantic errors are the equivalent of saying something in correct English that isn’t what you wanted to say. Examples are adding instead of multiplying or using > in place of < or "I'm going to Programming Games class in Social Sciencs."

Error console In Firefox (mac) under Tools, click on Error console to see syntactic errors. –Click on Clear to remove errors In Firefox and some other browsers on the PC, you can type in javascript: in the location field Google Chrome: claims facilities for testing, but…I can't quite make them work.

Homework [Catch up, including uploading projects, preparing index.html file] Work on your project. Project due 3/21. Midterm 3/17