# MCS-170 The Nature of Computer Science

## Chapter 5 and Exam Review

## 1. Using Numbers in JavaScript - Part II

- Use the predefined function
`parseFloat("3.15")`

to convert a string (`"3.15"`

)
into its corresponding number (`3.15`

)
- myNumber = prompt("Enter a number", ""); Returns
a String

- myNumber = parseFloat(myNumber); Converts
the string data to a number

- Large numbers are expressed in Scientific
Notation
`6.02e23 // this means 6.02 times 10 to the 23rd power`

- Numbers in JavaScript are represented in memory cells of 64-bits

- This means only a finite range of numbers can be stored!

- Example (1e308 is a
number, 1e309 is too big!)

- Largest number is 1.79E+308
- Smallest (positive) number is 5e-324

- Predefined Numeric Functions:
- Math.sqrt(x); returns the
square root of x

- Math.max(a,b); returns the larger of a and b

- Math.min(x,y); returns the smaller of x and y
- Math.pow(x,y); returns x to the y power

- Math.abs(n); returns the
absolute value of n

- Math.floor(y); returns the largest
integer less than or equal to y

- Math.ceil(x); returns the
smallest integer greater than or equal to x

- Math.round(a); returns the rounded-off
integer to a
- Math.random(); returns a random number that is
greater than or equal to 0 and less than 1.
- Example (Discuss how math
functions work)

## 2. Using Strings in JavaScript

- A JavaScript string is any sequence of characters

- String literals
always appear between quotes
- Examples of string literals
`"Please enter your name"`

`"3.15"`

`'Mickey Mouse'`

```
"This is an example of a \" double-quote \" used in a
string"
```

- Example

## 3. Review for Exam 1

- You may bring in a notebook-sized paper with your notes written on one side.

No computer-generated printout allowed.
- Review the Chapter Summaries at the end of Chapters 1, 2, 3, 4,
and 5
- Review the Homework sets 1 and 2
- Review the Ideas presented in the Projects
- Exam will have tree types of questions:
- True - False
- Short description of terms
- HTML and JavaScript

- Be prepared to write HTML code for illustrating various document
components such as links, bold text, paragraphs, etc.
- Be prepared to write JavaScript commands to carry out the five
capabilities discussed so far:

- prompting for input
- using variables
- writing to a web page
- converting strings to numbers
- using pre-defined functions