Skip to content

Commit 207be2d

Browse files
feat: adds mattieweathersby readme file for lesson04 homework (#138)
1 parent 53f8584 commit 207be2d

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
## Typescript Implementation
2+
```typescript
3+
function checkPrime(num: number): boolean{
4+
if (num < 2) {
5+
return false;
6+
}
7+
for (let i = 2; i < num; i++) {
8+
if (num % i === 0) {
9+
return false;
10+
}
11+
}
12+
return true;
13+
```
14+
15+
## Javascript Implementation
16+
```javescript
17+
function checkPrime(num) {
18+
if (num < 2) {
19+
return false;
20+
}
21+
for (let i = 2; num; i++) {
22+
if (num % i === 0) {
23+
return false;
24+
}
25+
}
26+
return true;
27+
}
28+
```
29+
30+
## Explanation
31+
Typescript implementation uses num that takes a single argument `number`. It returns true if the number is even (i.e., when the remainder of the division of the number by 2 is zero), otherwise, it returns `false`. Uses console.log to call functions and printing to console/output.
32+
33+
Example Usage:
34+
35+
console.log(checkPrime(2)); // true
36+
37+
console.log(checkPrime(4)); // false
38+
39+
Javascript implementation uses the same function `num` that takes a single argument `number`. It returns true using the same logic as typescript and `false` otherwise. ses console.log to call functions and printing to console/output.
40+
41+
Example Usage:
42+
43+
console.log(checkPrime(2)); // true
44+
45+
console.log(checkPrime(4)); // false
46+
47+
### Differences
48+
1. **Syntax**:
49+
While typescript requires annotations, javascript is a bit different because you don't need to use `:number` or `:boolean`

0 commit comments

Comments
 (0)