  @mcuringa/

# function-exercises ## #thinkjs #functions #practice

main.js
```1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
```
```// You can use this repl as a template
// for the chapter 3 function exercises
// from Think JS
// https://mcuringa.github.io/think-js/#exercises

// I've created a skeleton for the first 2
// functions. The rest you will have to do

// Write a void (non-fruitful) function to that prints out a “hello” message. Your function should declare 3 parameters: firstName, lastName, and title. title will be Mr., Ms., Dr., etc. The function should print a message like this one: Hello Dr. Matthew Curinga.

function hello(firstName, lastName, title) {

}

// problem 2
// Write a function half(num) which returns the value of num divided by 2.

function half(num) {

}

//test that half() works as expected
console.assert(half(4) === 2, "Expected half(4) to be 2")

// problem 3
// Write a function triple(num) which return num * 3.

// problem 4
// Write a function areaOfACircle(r) which returns the area of a circle of radius r. For the value of PI, use the constant Math.PI
// (Hint: if you can’t remember how to find the area of a circle, look it up or ask a friend.)

// problem 5
// Write a function hypotenuse(a, b) which calculates the hypotonuse of a right triangle when given the length of sides a and b. Use the Pythagorean theorem a^2 + b^2 = c^2.
// Note, you will need to be able to calculate square roots to solve this problem. You can use the build in math function Math.sqrt.

// problem 6
// (hard bonus) Write a function called distance(x1, y1, x2, y2) which calculates the distance between the point at (x1, y1) and (x2, y2) on a Cartesian Plane. You can find the formula for this at http://www.mathsisfun.com/algebra/distance-2-points.html
// Use the hypotenuse function from exercise 5 to compose this function.

```
Babel Compiler v6.4.4 Copyright (c) 2014-2015 Sebastian McKenzie