Skip to content

Commit be11696

Browse files
first commit
0 parents  commit be11696

File tree

491 files changed

+24128
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

491 files changed

+24128
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
.DS_Store
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const helloWorld = require('./hello-world');
2+
3+
const result = helloWorld();
4+
5+
console.log(result);
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
function helloWorld() {
2+
// Return the string 'Hello World!'
3+
return 'Hello World!';
4+
}
5+
6+
module.exports = helloWorld;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
function helloWorld() {
2+
return 'Hello World!';
3+
}
4+
5+
module.exports = helloWorld;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const helloWorld = require('./hello-world');
2+
3+
test("Returning 'Hello, World!' as a string", () => {
4+
const result = helloWorld();
5+
expect(result).toBe('Hello World!');
6+
});
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Challenge: Hello World Sample Challenge
2+
3+
This is a practice challenge to show you how things are set up and how to test, etc.
4+
5+
## Instructions
6+
7+
Write a function called `helloWorld` that returns a string of 'Hello World!'.
8+
9+
### Function Signature
10+
11+
```js
12+
/**
13+
* Returns a string containing 'Hello World!'.
14+
* @returns {string} - The string 'Hello World!'.
15+
*/
16+
function helloWorld(): string;
17+
```
18+
19+
### Examples
20+
21+
```JS
22+
helloWorld() // 'Hello World!'
23+
```
24+
25+
### Constraints
26+
27+
I will put any constraints here. They will vary depending on the challenge.
28+
29+
- The function must return a string
30+
31+
### Hints
32+
33+
- I will put a couple hints here. You can choose to use them or not.
34+
35+
## Solutions
36+
37+
<details>
38+
<summary>Click For Solution</summary>
39+
40+
```JS
41+
function printHelloWorld() {
42+
return 'Hello World!';
43+
}
44+
```
45+
46+
### Explanation
47+
48+
I will put the explanation to the solution here. The length and depth of the explanation will vary depending on the challenge.
49+
50+
</details>
51+
52+
### Test Cases
53+
54+
The Jest tests will go here. They are already included in the course files. You just need to run `npm test`. Sometimes I will also put manual tests here.
55+
56+
```JS
57+
test("Returning 'Hello, World!' as a string", () => {
58+
const result = helloWorld();
59+
expect(result).toBe('Hello World!');
60+
});
61+
```
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const getSum = require('./get-sum');
2+
3+
const result = getSum(1, 10);
4+
5+
console.log(result);
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
function getSum(a, b) {
2+
// return the sum of a and b
3+
return a + b;
4+
}
5+
6+
module.exports = getSum;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
function getSum(a, b) {
2+
return a + b;
3+
}
4+
5+
module.exports = getSum;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const getSum = require('./get-sum');
2+
3+
test('Calculating the sum of two numbers', () => {
4+
// Test case inputs
5+
const num1 = 5;
6+
const num2 = 7;
7+
8+
// Call the function
9+
const result = getSum(num1, num2);
10+
11+
// Check if the result is equal to the expected sum
12+
expect(result).toBe(12);
13+
});
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Challenge: Get Sum
2+
3+
This is another very basic practice challenge just to get you into the hang of things.
4+
5+
## Instructions
6+
7+
Write a function called `getSum` that takes in two numbers and returns the sum of those two numbers.
8+
9+
### Function Signature
10+
11+
```js
12+
/**
13+
* Returns the sum of two numbers.
14+
* @param {number} a - The first number.
15+
* @param {number} b - The second number.
16+
* @returns {number} - The sum of the two numbers.
17+
*/
18+
function getSum(a: number, b: number): number;
19+
```
20+
21+
### Examples
22+
23+
```JS
24+
getSum(1, 2) // 3
25+
getSum(10, 5) // 15
26+
getSum(2, 2) // 4
27+
getSum(10, 5) // 15
28+
```
29+
30+
### Constraints
31+
32+
- The function must return a number
33+
34+
### Hints
35+
36+
- You can use the `+` operator to add two numbers together.
37+
38+
## Solutions
39+
40+
<details>
41+
<summary>Click For Solution</summary>
42+
43+
```JS
44+
function getSum(a, b) {
45+
return a + b;
46+
}
47+
```
48+
49+
### Explanation
50+
51+
This is a pretty simple challenge. We created a function that takes in two values and we added those two values together. We then returned the sum of those two values.
52+
53+
</details>
54+
55+
### Test Cases
56+
57+
```JS
58+
test('Calculating the sum of two numbers', () => {
59+
// Test case inputs
60+
const num1 = 5;
61+
const num2 = 7;
62+
63+
// Call the function
64+
const result = getSum(num1, num2);
65+
66+
// Check if the result is equal to the expected sum
67+
expect(result).toBe(12);
68+
});
69+
```
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const calculator = require('./calculator');
2+
3+
const result = calculator(1, 2, '+');
4+
5+
console.log(result);
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Solution 1
2+
function calculator(num1, num2, operator) {
3+
// Declare a variable to store the result
4+
let result;
5+
6+
// Use a switch statement to determine which operation to perform
7+
switch (operator) {
8+
case '+':
9+
result = num1 + num2;
10+
break; // Break out of the switch statement
11+
case '-':
12+
result = num1 - num2;
13+
break;
14+
case '*':
15+
result = num1 * num2;
16+
break;
17+
case '/':
18+
result = num1 / num2;
19+
break;
20+
default:
21+
// If the operator is not one of the above, throw an error
22+
throw new Error('Invalid operator');
23+
}
24+
25+
return result;
26+
}
27+
28+
// Solution 2
29+
function calculator(num1, num2, operator) {
30+
// Declare a variable to store the result
31+
let result;
32+
33+
// Use if/else if/else statements to determine which operation to perform
34+
if (operator === '+') {
35+
result = num1 + num2;
36+
} else if (operator === '-') {
37+
result = num1 - num2;
38+
} else if (operator === '*') {
39+
result = num1 * num2;
40+
} else if (operator === '/') {
41+
result = num1 / num2;
42+
} else {
43+
// If the operator is not one of the above, throw an error
44+
throw new Error('Invalid operator');
45+
}
46+
47+
return result;
48+
}
49+
50+
module.exports = calculator;
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// function calculator(num1, num2, operator) {
2+
// let result;
3+
4+
// switch (operator) {
5+
// case '+':
6+
// result = num1 + num2;
7+
// break;
8+
// case '-':
9+
// result = num1 - num2;
10+
// break;
11+
// case '*':
12+
// result = num1 * num2;
13+
// break;
14+
// case '/':
15+
// result = num1 / num2;
16+
// break;
17+
// default:
18+
// throw new Error('Invalid operator');
19+
// }
20+
21+
// return result;
22+
// }
23+
24+
function calculator(num1, num2, operator) {
25+
let result;
26+
27+
if (operator === '+') {
28+
result = num1 + num2;
29+
} else if (operator === '-') {
30+
result = num1 - num2;
31+
} else if (operator === '*') {
32+
result = num1 * num2;
33+
} else if (operator === '/') {
34+
result = num1 / num2;
35+
} else {
36+
throw new Error('Invalid operator');
37+
}
38+
39+
return result;
40+
}
41+
42+
module.exports = calculator;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const calculator = require('./calculator');
2+
3+
test('Performing arithmetic operations using the calculator function', () => {
4+
// Test case inputs
5+
const num1 = 5;
6+
const num2 = 7;
7+
8+
// Addition
9+
expect(calculator(num1, num2, '+')).toBe(12);
10+
11+
// Subtraction
12+
expect(calculator(num1, num2, '-')).toBe(-2);
13+
14+
// Multiplication
15+
expect(calculator(num1, num2, '*')).toBe(35);
16+
17+
// Division
18+
expect(calculator(num1, num2, '/')).toBeCloseTo(0.7143, 4);
19+
});

0 commit comments

Comments
 (0)