Skip to content

Commit 9671529

Browse files
author
“dlipscomb244”
committed
Merge branch 'lesson_05' of https://github.com/dlipscomb244/code-differently-24-q4 into lesson_05
2 parents f918d7e + 37d1107 commit 9671529

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

lesson_04/dennislipscomb/README04.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
## Javascript
2+
```Javascript
3+
4+
function isPrime (num) {
5+
/* first condtion is checking if 7 is less than or equal to 1. */
6+
if (num <= 1) return false;
7+
/*checking if the number has a remainder or 0 if divided 2 */
8+
for (let i = 2; i < num; i++) {
9+
if (num% i === 0)
10+
return false;
11+
}
12+
return true;}
13+
14+
15+
console.log(isPrime (7))
16+
```
17+
18+
## Java
19+
```Java
20+
21+
public class PrimeChecker {
22+
23+
public static boolean isPrime(int num) {
24+
// First condition: check if num is less than or equal to 1
25+
if (num <= 1) return false;
26+
27+
// Check for factors from 2 to num - 1
28+
for (int i = 2; i < num; i++) {
29+
if (num % i == 0) {
30+
return false;
31+
}
32+
}
33+
return true;
34+
}
35+
36+
public static void main(String[] args) {
37+
System.out.println(isPrime(11)); // Test the function
38+
}
39+
}
40+
```
41+
42+
## Explination
43+
44+
In javascript, the function "isPrime" is checking if the number is less than or equal to 1. if so the fuction will fail. If it passes it will run the next fuction to see if the input has a remainder of 0 if divided by 2.
45+
46+
In Java, the function "isPrime(int num)" is checking if the number is less than or equal to 1. if the number is indeed greater than or less than it will return false. if true the function will run through a for loop to determine if divided by 2 will the remainder be 0.
47+
48+
49+
### Differences
50+
51+
Java and Javascript have numerous similarites but arent related. Java runs a more strict ruleset with certain elements such capital vs lower case letters where as javascript is more lenient in its functionality. In javascript the print out to test the fuction is console.log where as in Java the print out is system.out.println
52+
53+
54+
#### Citing
55+
56+
I got my Javascript code from a youtube video https://www.youtube.com/watch?v=ZdoiS_qUOSE I took that code and pasted it into https://playcode.io/ to test if the code worked. I had to make a few changes through trial and error. Once i got the correct code, i asked chatGPT to convert the javascript into java.
57+

0 commit comments

Comments
 (0)