how do you represent a number with no value? mathematicians defined the “number” 0 (zero) how...

4
PROGRAMMING PART IV USNA SI110

Upload: basil-walton

Post on 19-Jan-2016

214 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: How do you represent a number with no value?  Mathematicians defined the “number” 0 (zero)  How do we represent a string with no value?  Use an empty

PROGRAMMINGPART IV

USNA SI110

Page 2: How do you represent a number with no value?  Mathematicians defined the “number” 0 (zero)  How do we represent a string with no value?  Use an empty

Programming Part IV 2

The Empty String

How do you represent a number with no value? Mathematicians defined the “number” 0 (zero)

How do we represent a string with no value? Use an empty string

What is an empty string? String of length zero Defined as “”

Open and close quote with no characters between Often used to initialize a string variable that will

be used later

Page 3: How do you represent a number with no value?  Mathematicians defined the “number” 0 (zero)  How do we represent a string with no value?  Use an empty

Programming Part IV 3

Manipulating ASCII Values

Two string-related functions for dealing with ASCII values .charCodeAt(i)

Returns the ASCII value for the character at index i Returns the ASCII value as a Number (decimal)

“abcd”.charCodeAt(2) → 99 (ASCII value for “c”) String.fromCharCode(i)

Returns a single-character string Character is the ASCII character at code i

Character code can be in decimal or hex String.fromCharCode(99) → “c” String.fromCharCode(0x63) → “c”

(99 = 0x63)

Page 4: How do you represent a number with no value?  Mathematicians defined the “number” 0 (zero)  How do we represent a string with no value?  Use an empty

Programming Part IV 4

Examples

Random password generator Lowercase conversion