Skip to content

Commit 3e40fd7

Browse files
committed
Finish adding functions
1 parent 1a91e7f commit 3e40fd7

File tree

4 files changed

+216
-122
lines changed

4 files changed

+216
-122
lines changed

README.md

+76-16
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,48 @@ js-functions
33

44
Javascript Function Exercises
55

6+
Create 20 functions by following the comments in `functions.js`.
7+
8+
---
9+
10+
numberToString(n)
11+
-----------------------------
12+
Converts a number a string.
13+
14+
**Parameters**
15+
16+
**n**: number
17+
18+
**Returns**: string, the number as a string
19+
20+
increase(n)
21+
-----------------------------
22+
Adds one to a given number
23+
24+
**Parameters**
25+
26+
**n**: number
27+
28+
**Returns**: number
29+
30+
decrease(n)
31+
-----------------------------
32+
Subtracts one from a given number
33+
34+
**Parameters**
35+
36+
**n**: number
37+
38+
**Returns**: number
39+
640
add(x, y)
741
-----------------------------
842
Adds two numbers.
943

1044
**Parameters**
1145

1246
**x**: number
13-
circumference
47+
1448
**y**: number
1549

1650
**Returns**: number, the sum
@@ -51,19 +85,19 @@ Divides the first number by the second.
5185

5286
**Returns**: number, the quotient
5387

54-
numberToString(n)
88+
square(x,)
5589
-----------------------------
56-
Converts a number a string.
90+
Multiplies a number by itself.
5791

5892
**Parameters**
5993

60-
**n**: number
94+
**x,**: number, number to be squared
6195

62-
**Returns**: string, the number as a string
96+
**Returns**: number, squared
6397

6498
calculate(operation, x, y)
6599
-----------------------------
66-
Prints out the equation: (i.e.) "1 + 5 = 6" or "8 / 2 = 4"
100+
Prints out the equation: (i.e.) "1 + 5 = 6" or "8 / 2 = 4".
67101
Returns the result.
68102

69103
**Parameters**
@@ -76,6 +110,42 @@ Returns the result.
76110

77111
**Returns**: number, the result
78112

113+
isGreaterThan(x, y)
114+
-----------------------------
115+
Returns true if x is greater than y
116+
117+
**Parameters**
118+
119+
**x**: number
120+
121+
**y**: number
122+
123+
**Returns**: boolean, x is larger than y
124+
125+
isLessThan(x, y)
126+
-----------------------------
127+
Returns true if x is less than y
128+
129+
**Parameters**
130+
131+
**x**: number
132+
133+
**y**: number
134+
135+
**Returns**: boolean, x is smaller than y
136+
137+
areEqual(x, y)
138+
-----------------------------
139+
Returns true if a and b are equal
140+
141+
**Parameters**
142+
143+
**x**: number
144+
145+
**y**: number
146+
147+
**Returns**: boolean, the numbers are equal
148+
79149
minimum(a, b)
80150
-----------------------------
81151
Returns the smallest value of two numbers.
@@ -148,16 +218,6 @@ set its `reviews` field to 1.
148218
**restaurant**: object, represents a restaurant
149219

150220

151-
square(x,)
152-
-----------------------------
153-
Multiplies a number by itself.
154-
155-
**Parameters**
156-
157-
**x,**: number, number to be squared
158-
159-
**Returns**: number, squared
160-
161221
combine(word1, word2)
162222
-----------------------------
163223
Joins two strings with a space.

functions.js

+139
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
/**
2+
* Converts a number a string.
3+
* @param {number} n
4+
* @return {string} the number as a string
5+
*/
6+
7+
/**
8+
* Adds one to a given number
9+
* @param {number} n
10+
* @return {number}
11+
*/
12+
13+
/**
14+
* Subtracts one from a given number
15+
* @param {number} n
16+
* @return {number}
17+
*/
18+
19+
/**
20+
* Adds two numbers.
21+
* @param {number} x
22+
* @param {number} y
23+
* @return {number} the sum
24+
*/
25+
26+
/**
27+
* Subtracts the second number from the first.
28+
* @param {number} x
29+
* @param {number} y
30+
* @return {number} the difference
31+
*/
32+
33+
/**
34+
* Multiplies two numbers.
35+
* @param {number} x
36+
* @param {number} y
37+
* @return {number} the product
38+
*/
39+
40+
/**
41+
* Divides the first number by the second.
42+
* @param {number} x
43+
* @param {number} y
44+
* @return {number} the quotient
45+
*/
46+
47+
/**
48+
* Multiplies a number by itself.
49+
* @param {number} x, number to be squared
50+
* @return {number} squared
51+
*/
52+
53+
/**
54+
* Prints out the equation: (i.e.) "1 + 5 = 6" or "8 / 2 = 4".
55+
* Returns the result.
56+
* @param {string} operation "add", "subtract", "multiply", or "divide"
57+
* @param {number} x
58+
* @param {number} y
59+
* @return {number} the result
60+
*/
61+
62+
/**
63+
* Returns true if x is greater than y
64+
* @param {number} x
65+
* @param {number} y
66+
* @return {boolean} x is larger than y
67+
*/
68+
69+
/**
70+
* Returns true if x is less than y
71+
* @param {number} x
72+
* @param {number} y
73+
* @return {boolean} x is smaller than y
74+
*/
75+
76+
/**
77+
* Returns true if a and b are equal
78+
* @param {number} x
79+
* @param {number} y
80+
* @return {boolean} the numbers are equal
81+
*/
82+
83+
/**
84+
* Returns the smallest value of two numbers.
85+
* @param {number} a
86+
* @param {number} b
87+
* @return {number} the smallest number
88+
*/
89+
90+
/**
91+
* Returns the largest value of two numbers.
92+
* @param {number} a
93+
* @param {number} b
94+
* @return {number} the largest number
95+
*/
96+
97+
/**
98+
* Returns true if `n` is even.
99+
* @param {number} n
100+
* @return {boolean} the number is even
101+
*/
102+
103+
/**
104+
* Returns true if `n` is odd.
105+
* @param {number} n
106+
* @return {boolean} the number is odd
107+
*/
108+
109+
/**
110+
* Returns a letter grade.
111+
* "A": 90-100%
112+
* "B": 80-89%
113+
* "C": 70-79%
114+
* "D": 60-69%
115+
* "F": 0-59%
116+
* @param {number} score
117+
* @param {number} total maximum possible score
118+
* @return {string} the score represented as a letter grade
119+
*/
120+
121+
/**
122+
* Checks if arestaurant` object has are `views` field.
123+
* If it does, increase it by 1. If it does not,
124+
* set itsreviews` field to 1.
125+
* @param {object} restaurant represents a restaurant
126+
*/
127+
128+
/**
129+
* Joins two strings with a space.
130+
* @param {string} word1
131+
* @param {string} word2
132+
* @return {string} joined the words joined with a space
133+
*/
134+
135+
/**
136+
* Returns a circle object with the properties `circumferance` and `area`.
137+
* @param {number} radius
138+
* @return {object} circle
139+
*/

index.html

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
<script src="lib/js/chai.js" type="text/javascript"></script>
1515
<script src="lib/js/sinon-chai.js" type="text/javascript"></script>
1616
<script src="lib/js/sinon.js" type="text/javascript"></script>
17+
<script src="functions.js" type="text/javascript"></script>
1718
<script src="script.js" type="text/javascript"></script>
1819
<script>mocha.setup('bdd');</script>
1920
<script src="test/test-script.js"type="text/javascript"></script>

script.js

-106
Original file line numberDiff line numberDiff line change
@@ -1,106 +0,0 @@
1-
/**
2-
* Adds two numbers.
3-
* @param {number} x `
4-
* @param {number} y `
5-
* @return {number} the sum
6-
*/
7-
8-
/**
9-
* Subtracts the second number from the first.
10-
* @param {number} x `
11-
* @param {number} y `
12-
* @return {number} the difference
13-
*/
14-
15-
/**
16-
* Multiplies two numbers.
17-
* @param {number} x `
18-
* @param {number} y `
19-
* @return {number} the product
20-
*/
21-
22-
/**
23-
* Divides the first number by the second.
24-
* @param {number} x `
25-
* @param {number} y `
26-
* @return {number} the quotient
27-
*/
28-
29-
/**
30-
* Converts a number a string.
31-
* @param {number} n `
32-
* @return {string} the number as a string
33-
*/
34-
35-
/**
36-
* Prints out the equation: (i.e.) "1 + 5 = 6" or "8 / 2 = 4".
37-
* Returns the result.
38-
* @param {string} operation "add", "subtract", "multiply", or "divide"
39-
* @param {number} x `
40-
* @param {number} y `
41-
* @return {number} the result
42-
*/
43-
44-
/**
45-
* Returns the smallest value of two numbers.
46-
* @param {number} a `
47-
* @param {number} b `
48-
* @return {number} the smallest number
49-
*/
50-
51-
/**
52-
* Returns the largest value of two numbers.
53-
* @param {number} a `
54-
* @param {number} b `
55-
* @return {number} the largest number
56-
*/
57-
58-
/**
59-
* Returns true if `n` is even.
60-
* @param {number} n `
61-
* @return {boolean} the number is even
62-
*/
63-
64-
/**
65-
* Returns true if `n` is odd.
66-
* @param {number} n `
67-
* @return {boolean} the number is odd
68-
*/
69-
70-
/**
71-
* Returns a letter grade.
72-
* "A": 90-100%
73-
* "B": 80-89%
74-
* "C": 70-79%
75-
* "D": 60-69%
76-
* "F": 0-59%
77-
* @param {number} score `
78-
* @param {number} total maximum possible score
79-
* @return {string} the score represented as a letter grade
80-
*/
81-
82-
/**
83-
* Checks if a `restaurant` object has a `reviews` field.
84-
* If it does, increase it by 1. If it does not,
85-
* set its `reviews` field to 1.
86-
* @param {object} restaurant represents a restaurant
87-
*/
88-
89-
/**
90-
* Multiplies a number by itself.
91-
* @param {number} x, number to be squared
92-
* @return {number} squared
93-
*/
94-
95-
/**
96-
* Joins two strings with a space.
97-
* @param {string} word1 `
98-
* @param {string} word2 `
99-
* @return {string} joined the words joined with a space
100-
*/
101-
102-
/**
103-
* Returns a circle object with the properties `circumferance` and `area`.
104-
* @param {number} radius `
105-
* @return {object} circle
106-
*/

0 commit comments

Comments
 (0)