Textbook Notes
(362,755)

United States
(204,198)

Marist College
(317)

Computer Science
(9)

CMPT 120L-115
(9)

Matthew Johnson
(9)

Chapter 7

# Chapter7.docx

Unlock Document

Marist College

Computer Science

CMPT 120L-115

Matthew Johnson

Fall

Description

A Balanced Introduction to Computer Science, 3 Edition
David Reed
Chapter Seven: Functions and Randomness
A. Predefined JavaScript Functions
1. Functions are identified by name with the inputs to the function paced
in parentheses
a. A unit of computational abstraction
b. Example: to convert a string to its corresponding number,
add parseFloat function and obtain value
c. Calling – applying a function to inputs
i. Return value – output of the function
ii. Example:
amount=parseFloat(document.getElementById(‘amoun
tBox’).value);
2. Math Functions
a. Prefix is Math.
i. Signifies that functions are a part of a library of
mathematical routines
ii. Example: Math.sqrt (gives square root)
Math.max (gives largest of 2 inputs)
3. Raising Numbers to a Power 3
a. Math.pow (2, 3) returns 2 =8
i. Can include negative exponents
4. Generating Random Numbers
a. A function is a mapping from some number of inputs to a
single output
b. Math.random has no inputs
i. Pseudorandom results: the function uses an algorithm
to generate seemingly random values from within the

More
Less
Related notes for CMPT 120L-115