Download presentation

Presentation is loading. Please wait.

1
8 November Forms and JavaScript

2
Types of Inputs Radio Buttons (select one of a list) Checkbox (select as many as wanted) Text inputs (user types text) Select List (select from a list) Buttons (click on or off)

3
Select List Syntax <select name=“name for this list” size=“number-of-entries-to-show”> Text to be displayed … What it does Lets the user select one entry from a list of fixed text (extension to select multiples) Optional initial value Displayed text part of tags Scroll bar built in How it does it Own variable Value is the selected entry

4
Buttons Syntax <input type=“button” value=“name to be displayed” onclick=“what to do when the button is clicked”> What it does Lets you perform an action Need to learn a little Javascript Lots of different events (e.g., mouseover), but we’ll only worry about “onclick”

5
JavaScript

6
Writing a Program Want to be able to describe a program in human comprehensible terms Programs translates from those terms to machine comprehensible Same precision is needed, but do not worry about where in the computer information is stored what instructions look like What you write is referred to as code

7
Executing a Program Two types of translators compiler and interpreter Compiler creates a program that can be stored and run later without the compiler Interpreter follows the instructions that are described and is always used when running the program Writing a program is basically the same in either case

8
To write a program Basically two parts: the information and what to do with it 1. Identify the data that you are going to use 2. Describe what to do with the data: the algorithm

9
Example: Calculator Data The numbers that are going to be processed The result Memory holders What to do with it Compute the requested functions Display the results

10
Example: Sales Data The items for sale: name, cost The person buying: name, address, credit card information The actual order: quantity of each item purchased What to do with it Compute the cost Display the current order

11
General JavaScript Rules Case-sensitive Taxrate, TaxRate, and taxrate are all different! Uses ; to end statements Similar to a period in English Unlike people, computers can get confused if you forget it

12
Creating a Variable Review: Computers store values in memory Refer to the place, not the value The location is referred to as a variable A variable’s name is called an identifier Need to tell computer The name that you are going to use What value it starts with How to interpret the bits: the type of data Some language require that you tell it Some deduce it based on what you assign to it Some permit either (JavaScript)

13
Types of Data (JavaScript) Numbers Integers Floating point numbers Strings Booleans

14
Representing Integers Additive system lllll lllll Every item represents 1 Examples of additive systems? Positional system Value = face * place 37 = 3*10 + 7*1

15
Positional System Base = number of different values in a position Base 10 = 10 values: 0-9 Base 2 = 2 values: 0-1 Value of each position = power of base b 4 b 3 b 2 b 1 b 0

16
Example in Base 2 1010 = 1 x 2 3 + 0 x 2 2 + 1 x 2 1 + 0 x 2 0 1 x 8 + 0 x 4 + 1 x 2 + 0 x 1 8 + 0 +2 + 0 8 + 2 10

17
Integers What information is needed? Sign and magnitude We use sign-magnitude notation +1, -1 Machine arithmetic is harder this way

18
How Integers are Stored Two’s complement We’re not going to look at how it works in detail, but there important characteristics: Maximum value that can be stored If checking is not done correctly, positive numbers that are too big will appear to be negative numbers

19
Example Assume that we only have 4 bits to work with Largest positive number is 7 = 0111 Adding 1 to that number 0111 + 1 1000 Turns out that is the representation for the largest negative number (-8)

20
Why Do You Care? Properly working program: message that says that the number is too large Erroneous program: you get a negative number when you expect a positive one

21
Floating Point Numbers Scientific notation 1.452 x 10 17 Mantissa exponent Need to store larger numbers than possible in integers Use sign magnitude: high order bit = sign Then store exponent and mantissa Can be single or double word Precision of the number

22
IEEE Floating Point Standard (Single Precision) The Sign Bit (1 bit) 0 denotes a positive number; 1 denotes a negative number The Exponent (8 bits) Needs to represent both positive and negative exponents Add a bias of 127. Subtract 127 to see the real exponent The Mantissa (23 bits) Implicit leading bit of 1 and the fraction bits Adjust the value so that the leading bit is 1, then drop it. Example: 5.00 x 10 0 = 0.05 x 10 2 = 5000 x 10 -3 In binary 101 x 10 0 = 1.01 x 10 2 Decimal point is to the left of the stored number (normalized form) 5 = 1 10000001 01000000000000000000000

23
Floating Point: Errors In decimal, 1/3 can’t be represented as a fixed decimal number Lots of examples in binary as well Problems occur Converting between integer and floating point Displaying results Whittaker, How to Break Software

24
Text Need to represent characters All data in the computer is stored as _____ Letter a question of interpretation Also includes some control: new line, tab, … Not font Representations ASCII, EBCDIC, UNICODE, … ASCII simplest

25
Valuable Characteristics Collating sequence Simple upper/lower case Support of all languages Other?

26
ASCII collating For collating sequence, where should punctuation be? General rule: space < punctuation < number < letter How to deal with case? Collating sequence is case insensitive Need to force to uppercase

27
Multiple languages Used to have complete different set of encodings for each language, called code pages Unicode is fundamentally 2-bytes Preserves the ASCII values Doubles the size of files www.unicode.org

28
Boolean Two values: true or false

Similar presentations

© 2020 SlidePlayer.com Inc.

All rights reserved.

To make this website work, we log user data and share it with processors. To use this website, you must agree to our Privacy Policy, including cookie policy.

Ads by Google