@mcuringa/

# While Loop Exercises

## No description

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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
```
```// 1. **Sum range**
// Write a function sumRange(start, end) that sums
// (adds up) all of the numbers between start and end,
// including start and end. Return the sum (a number).

function sum(start, end) {

}

// 2. **Square count**
// Revise the code below for Newton’s method for calculating square roots.
// Instead of returning the square root, it should return the number of
// iterations required to find the square root.

function sqrt(n) {
let approx = n/2;   // Start with some or other guess at the answer
let better = (approx + n/approx)/2;
while (Math.abs(approx - better) > .001) {
approx = better;
better = (approx + n/approx)/2.0;
}
return better;
}

// 3. **Sum of odds**
// sumOfOdds(start, end) calculates and returns the sum
// of all of the odd numbers in the range start..end. It includes
// start and end if they are odd numbers.

function sumOfOdds(start, end) {

}

// 4. **Sum of Squares**
// Write a function that calculates and returns the sum of
// the squares of numbers in a range: sumOfSquare(start, end).
// The range includes start and end.

function sumOfSquare(start, end) {

}

// 5. **Greatest factor**
// Write a function greatestFactor(start, end, n) that returns the
// greatest (highest) factor of n in the range of numbers between
// start and end (including end).
// you must use a while loop

function greatestFactor(start, end, n) {

}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// these are extra practice/bonus questions

// 6. **Greatest Common Factor**
// Write a function gcf(a, b) that returns the greatest (highest number)
// that is a factor of both a and b.

function gcf(a, b) {

}

// 7. **Factorials**
// Write a function fact(n) which returns the factorial of n (n!).
// The factorial of a number is that number multiplied by all of the
// numbers between itself and 1, so the factorial of
// 4 is 4 x 3 x 2 x 1 = 24. In Javascript, we’d say fact(4) === 24.

function fact(n) {

}

// 8. **Fibonacci Sequence**
// https://www.mathsisfun.com/numbers/fibonacci-sequence.html
// Each term in the Fibonacci Sequence is calculated by adding the
// two previous numbers in the sequence together. The first two terms
// can by 0, and 1, so the next term is 1. The sequence begins
// 0, 1, 1, 2, 3, 5, 8, 13. Write a function fib(n) which returns
// the nth number in the sequence.
// So, fib(0) === 0, fib(3) === 5 and so on.

function fib(n){

}

// 9. **Armstrong Numbers**
// https://en.wikipedia.org/wiki/Narcissistic_number
// An Armstrong Number is a number where the sum of the digits
// raised to the number of digits in the number, equal the number itself. 153 is an Armstrong Number.
// It has 3 digits, so 13+53+33=1+125+27=1531^3 + 5^3 + 3^3 = 1 + 125 + 27 = 153 Write a function
// isArmstrong(n) that returns true if n is an Armstrong Number, or false if it isn’t.

function isArmstrong(n) {

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