Skip to content

Commit 3f57c1a

Browse files
committed
Finished boolean expression homework
1 parent 840208d commit 3f57c1a

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

lesson_07/conditionals/.env.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
HW_VERSION=your homework version here
1+
HW_VERSION=A

lesson_07/conditionals/src/part_a.ts

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@
55
* @return True if the age corresponds to a voting age and false otherwise.
66
*/
77
export function canVote(age: number): boolean {
8-
return false;
8+
if (age >=18){
9+
return true;
10+
}
11+
else{
12+
return false;
13+
}
914
}
1015

1116
/**
@@ -15,7 +20,11 @@ export function canVote(age: number): boolean {
1520
* @return The sum of all the values.
1621
*/
1722
export function addNumbers(values: number[]): number {
18-
return 0;
23+
let sum = 0;
24+
for (const value of values){
25+
sum +=value;
26+
}
27+
return sum;
1928
}
2029

2130
/**
@@ -25,5 +34,18 @@ export function addNumbers(values: number[]): number {
2534
* @return The factorial of n.
2635
*/
2736
export function computeFactorial(n: number): number {
28-
return 0;
37+
if (n === 0) {
38+
return 1;
39+
}
40+
if (n === 1) {
41+
return 1;
42+
}
43+
44+
let result = 1;
45+
46+
for (let i = 1; i <= n; i++) {
47+
result = result * i;
48+
}
49+
50+
return result;
2951
}

0 commit comments

Comments
 (0)