Skip to content

Commit 4fa8a3f

Browse files
authored
feat: adds JBey's code samples. (#153)
1 parent 3fcfc7e commit 4fa8a3f

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

lesson_04/JBey/README.md

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
## Python
2+
3+
```python
4+
def primeNumber(num):
5+
if num <= 1:
6+
return False
7+
8+
for i in range(2, int(num**0.5) + 1):
9+
if num % i == 0:
10+
return False
11+
12+
return True
13+
14+
print(is_prime(11))
15+
print(is_prime(4))
16+
print(is_prime(1))
17+
print(is_prime(13))
18+
```
19+
20+
## JavaScript
21+
22+
```javascript
23+
function primeNumber(num) {
24+
if (num <= 1) {
25+
return false;
26+
}
27+
28+
for (let i = 2; i <= Math.sqrt(num); i++) {
29+
if (num % i === 0) {
30+
return false;
31+
}
32+
}
33+
34+
return true;
35+
}
36+
37+
console.log(isPrime(11));
38+
console.log(isPrime(4));
39+
console.log(isPrime(1));
40+
console.log(isPrime(13));
41+
```
42+
43+
## Explanation
44+
45+
Both languages use a function that is called called "PrimeNumber" with an argument called "num" that a number in the code compares itself in order to see if it is an even number or not. They both use a .log system where you put in your arguments (or numbers) in order to see if they're a prime number or not.
46+
47+
JavaScript uses console.log() in order to output files to the console, while python uses print() instead of console.log(). JavaScript uses the word "function" to create a function, while python uses the word "def" to create a function. Python create another function called "range" when creating a for loop, whereas JavaScript does not create another function.

0 commit comments

Comments
 (0)