Skip to content

Commit 61c3de9

Browse files
authored
All exercises: Add four new exercises (#509)
* Add empty files to create outline * Add broken troubleshooting function * Import troubleshooting.js file * Test function to ensure numbers are added together * Describe exercise two * Test result for troubleshooting function * Add solution * Add empty files to create outline * Add broken numberChecker function * Export numberChecker function * Verify proper return value for numbers greater than or equal to ten * Verify proper return value for numbers less than ten * Add solution * Skip tests after the first one * Describe exercise three * Add empty files to create outline * Add math variables for the exercise * Verify that math-related variables are returning correct answers * Add solution * Add tests for solution * Describe exercise * Add comment to describe answer already given * Add empty files to create outline * Add example problem * Verify that example problem contains correct variables * Add boilerplate code required to begin exercise * Add progressive tests for exercise * Describe exercise * Adjust excessive indentation * Add hint using comment * Update with correct exercise heading * Update with correct exercise number * rename troubleshooting to addNumbers * Rename script to numberChecker * Rename math to mathEquations * Give undefined assignment to undeclared variables instead of null * Add solution * Add tests for the solution * rename follow to joinStrings * Improve hint * Add additional hint * Update exercise title to mathEquations * Move explanation for enabling tests to numberChecker exercise * Renumber repeatString * Renumber reverseString * Renumber removeFromArray * Renumber sumAll * Renumber leapYears * Renumber tempConversion * Renumber calculator * Renumber palindromes * Renumber fibonacci * Renumber getTheTitles * Renumber findTheOldest * Remove unnecessary mention of file name * Use bullet point for extended description of a step * Remove redundant snippet of comment already in the code * Use bullet points for extended descriptions of steps * Use syntax highlighting for code snippet * Clarify which file will be edited * Remove period * Add final instruction * Update reference to exercise file names * Remove unnecessary comment from solution * Add comment as reminder to not edit some of the code * Separate tests for steps two and three * Remove unnecessary comment from solution * Update wording * Remove additional space after periods
1 parent 278058d commit 61c3de9

File tree

78 files changed

+411
-28
lines changed

Some content is hidden

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

78 files changed

+411
-28
lines changed

01_helloWorld/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ In this directory you will find 2 other files:
66
1. `helloWorld.js`
77
2. `helloWorld.spec.js`
88

9-
This setup should be the same for all of the exercises. The plain javascript file is where you'll write your code, and the `spec` file contains the tests that verify your code is functional.
9+
This setup should be similar for all of the exercises. The plain javascript file is where you'll write your code, and the `spec` file contains the tests that verify your code is functional.
1010

1111
Let's look at the spec file first:
1212
```javascript
@@ -20,9 +20,9 @@ describe('Hello World', function() {
2020
```
2121
At the very top of the file we use `require()` to import the code from the javascript file (`helloWorld.js`) so that we can test it.
2222

23-
The next block (`describe()`) is the body of the test. Basically, all it's doing is running your code and testing to see if the output is correct. The `test()` function describes what should be happening in plain english and then includes the `expect()` function. For this simple example it should be pretty simple to read.
23+
The next block (`describe()`) is the body of the test. Basically, all it's doing is running your code and testing to see if the output is correct. The `test()` function describes what should be happening in plain english and then includes the `expect()` function. For this simple example it should be pretty simple to read.
2424

25-
For now you do not need to worry about how to write tests, but you should try to get comfortable enough with the syntax to figure out what the tests are asking you to do. Go ahead and run the tests by entering `npm test helloWorld.spec.js` in the terminal and watch it fail. The output from that command should tell you exactly what went wrong with your code. In this case, running the `helloWorld()` function should return the phrase 'Hello, World!' but instead it returns an empty string...
25+
For now you do not need to worry about how to write tests, but you should try to get comfortable enough with the syntax to figure out what the tests are asking you to do. Go ahead and run the tests by entering `npm test helloWorld.spec.js` in the terminal and watch it fail. The output from that command should tell you exactly what went wrong with your code. In this case, running the `helloWorld()` function should return the phrase 'Hello, World!' but instead it returns an empty string...
2626

2727
so let's look at the javascript file:
2828
```javascript
@@ -32,11 +32,11 @@ const helloWorld = function() {
3232

3333
module.exports = helloWorld
3434
```
35-
In this file we have a simple function called helloWorld that returns an empty string... which is exactly what our test was complaining about. The `module.exports` on the last line is how we export the function so that it can be imported with `require()` in the spec file.
35+
In this file we have a simple function called helloWorld that returns an empty string... which is exactly what our test was complaining about. The `module.exports` on the last line is how we export the function so that it can be imported with `require()` in the spec file.
3636

3737
Go ahead and see if you can make the test pass by editing the return value of the function, and then running the test file again.
3838

39-
Just to make sure, in case you're confused at this point, the test is telling you that running the function `helloWorld` should return the phrase `Hello, World!`. Punctuation and capitalization definitely matter here, so double check that if the test still isn't passing.
39+
Just to make sure, in case you're confused at this point, the test is telling you that running the function `helloWorld` should return the phrase `Hello, World!`. Punctuation and capitalization definitely matter here, so double check that if the test still isn't passing.
4040

4141
This is what the final function should look like:
4242
```javascript
@@ -47,4 +47,4 @@ const helloWorld = function() {
4747
module.exports = helloWorld
4848
```
4949

50-
For the most part we've set up these tests in such a way that you only have to write the code being tested. You should not have to worry about importing or exporting anything at this stage.. so just work around that bit of the code and write what it takes to make them pass!
50+
For the most part we've set up these tests in such a way that you only have to update or write the code being tested. You should not have to worry about importing or exporting anything at this stage.. so just work around that bit of the code and write what it takes to make them pass!

02_addNumbers/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Exercise 02 - addNumbers
2+
3+
Troubleshoot and modify the existing function so that it returns the digit 2. Avoid "hard coding" the result and try to use variables `a` and `b` to get the correct output.
4+
5+
Currently, it is not returning the correct value.
6+
7+
## Hints
8+
9+
- You only need to edit the strings on line 7.

02_addNumbers/addNumbers.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
function addNumbers() {
2+
const a = 1;
3+
const b = 1;
4+
5+
let result;
6+
7+
result = "a" + "b"; // <------ EDIT THIS LINE
8+
9+
return result;
10+
}
11+
12+
// Do not change this
13+
module.exports = addNumbers;

02_addNumbers/addNumbers.spec.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const addNumbers = require('./addNumbers')
2+
3+
describe('addNumbers', () => {
4+
test('adds the numbers together', () => {
5+
expect(addNumbers()).toEqual(2);
6+
});
7+
});
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
function addNumbers() {
2+
const a = 1;
3+
const b = 1;
4+
5+
let result;
6+
7+
result = a + b;
8+
9+
return result;
10+
}
11+
12+
module.exports = addNumbers;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const addNumbers = require('./addNumbers-solution')
2+
3+
describe('addNumbers', () => {
4+
test('adds the numbers together', () => {
5+
expect(addNumbers()).toEqual(2);
6+
});
7+
});

03_numberChecker/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Exercise 03 - numberChecker
2+
3+
Modify the code so it returns `true` when the number is greater than or equal to 10, and `false` if it is less than 10.
4+
5+
Currently, the code returns `true` if the number is `6`, otherwise, it returns `false`.
6+
7+
You may also notice that in this exercise, there are multiple tests (in the file `numberChecker.spec.js`). Only the first test is currently enabled. So after making sure that the first test passes, enable the next one by deleting the `.skip` portion from the `test.skip()` function. It is usually easier if you enable only one test a time, then edit your code so that it passes. You can keep enabling only one at a time until slowly but surely, they all pass!
8+
9+
- If running `npm test numberChecker.spec.js` returns results similar to what is shown below, make sure that you have enabled the rest of the tests, as described in the instructions above.
10+
11+
```
12+
Test Suites: 1 passed, 1 total
13+
Tests: 3 skipped, 1 passed, 4 total
14+
```
15+
16+
## Hints
17+
18+
- You only need to edit line 2.
19+
20+
- Look at the docs for comparison operators in JavaScript for a quick reference.

03_numberChecker/numberChecker.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
function numberChecker(number) {
2+
if (number === 6) {
3+
return true;
4+
} else {
5+
return false;
6+
}
7+
}
8+
9+
// Do not edit below this line
10+
module.exports = numberChecker;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const numberChecker = require('./numberChecker')
2+
3+
describe('numberChecker', () => {
4+
test('returns true when number is 1000', () => {
5+
expect(numberChecker(1000)).toEqual(true);
6+
});
7+
test.skip('returns true when number is 10', () => {
8+
expect(numberChecker(10)).toEqual(true);
9+
});
10+
test.skip('returns false when number is 9', () => {
11+
expect(numberChecker(9)).toEqual(false);
12+
});
13+
test.skip('returns false when number is 6', () => {
14+
expect(numberChecker(6)).toEqual(false);
15+
});
16+
});
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
function numberChecker(number) {
2+
if (number >= 10) {
3+
return true;
4+
} else {
5+
return false;
6+
}
7+
}
8+
9+
module.exports = numberChecker;

0 commit comments

Comments
 (0)