fix(guide): simplify directory structure

This commit is contained in:
Mrugesh Mohapatra
2018-10-16 21:26:13 +05:30
parent f989c28c52
commit da0df12ab7
35752 changed files with 0 additions and 317652 deletions

View File

@ -0,0 +1,19 @@
---
title: Catch Arguments Passed in the Wrong Order When Calling a Function
---
## Catch Arguments Passed in the Wrong Order When Calling a Function
```javascript
function raiseToPower(b, e) {
return Math.pow(b, e);
}
```
- The above function is used to raise the base number `b` to the power of the exponent `e`.
- The function must be called specifically with variables in the correct order. Otherwise the function will mix up both variables and return an undesired answer.
- Make sure tha variable `power` is implementing the `raiseToPower` function correctly.
## Solution:
```javascript
let power = raiseToPower(base, exp);
```

View File

@ -0,0 +1,12 @@
---
title: Catch Missing Open and Closing Parenthesis After a Function Call
---
## Catch Missing Open and Closing Parenthesis After a Function Call
- Remember to add opening and closing parentheses when calling a function.
- FunctionName + ();
## Solution:
```javascript
let result = getNine();
```

View File

@ -0,0 +1,24 @@
---
title: Catch Misspelled Variable and Function Names
---
## Catch Misspelled Variable and Function Names
### Problem explanation:
Fix the two spelling errors in the code so the netWorkingCapital calculation works.
### Hint
Check the spelling of the first two variables against when it is used.
## Spoiler alert!
**Solution ahead!**
```javascript
// 'i' and 'e' swapped in "receivables" and missing 's' in "payables"
let receivables = 10;
let payables = 8;
let netWorkingCapital = receivables - payables;
console.log(`Net working capital is: ${netWorkingCapital}`);
```

View File

@ -0,0 +1,14 @@
---
title: Catch Mixed Usage of Single and Double Quotes
---
## Catch Mixed Usage of Single and Double Quotes
- Remember whether you choose to use single or double quotes, simply adding a `\` before the character will allow the character to fit in the string without closing either single or double quotes.
- The test cases will only be passed by using double quotes.
## Solution:
```javascript
//Solution1:
let innerHtml = "<p>Click here to <a href=\"#Home\">return home</a></p>";
console.log(innerHtml);
```

View File

@ -0,0 +1,55 @@
---
title: Catch Off By One Errors When Using Indexing
---
## Catch Off By One Errors When Using Indexing
### Basics
Due to the way JavaScript indexes work `firstFive` has **five elements** but they are indexed from **0 to 4**!
```javascript
console.log(len); // 5
console.log(firstFive[0]); // 1
/**/
console.log(firstFive[4]); // 5
console.log(firstFive[5]); // undefined
```
That should give you enough to grasp the limits of `firstFive`. Direct your attention to the loop. What does it do? You could try debugging it to find out!
### Debugging
You are given this code:
```javascript
for (let i = 1; i <= len; i++) {
console.log(firstFive[i]);
}
```
To debug this piece of code, use `console.clear()`. What would be the best place for it? The answer is right before the `for` statement!
```javascript
console.clear();
for (let i = 1; i <= len; i++) {
console.log(firstFive[i]);
}
```
Console output:
```text
Console was cleared.
2
3
4
5
undefined
```
### Analysis
Examine the output. Under these conditions the loop first prints the element positioned at 1... which is 2! It also tries to print the element indexed at 5 which is `undefined`.
This can be considered the point of this challenge. Keep `console.log()` and `console.clear()` present. They will help you understand how your code works.
### Solution
The most straightforward way to fix this is to alter the for() conditions.
Make `i` start at 0. Also the loop **should not** be executed for i == 5. In other words, the relationship between `i` and `len` should be `false` when i == 5. That can be achieved by using `i < len` (Is 5 < len? false, and the loop won't be executed!).
```javascript
for (let i = 0; i < len; i++) {
```
**Happy Coding!** :computer:
### Resources
- [For statements challenge at FreeCodeCamp](https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/iterate-with-javascript-for-loops)
- [For statements at MDN web docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Loops_and_iteration#for_statement)

View File

@ -0,0 +1,33 @@
---
title: Catch Unclosed Parentheses, Brackets, Braces and Quotes
---
## Catch Unclosed Parentheses, Brackets, Braces and Quotes
The reduce() method reduces an array to a single value. If you're not familiar with it, the following code shows an example of using the the method:
```
const array1 = [1, 2, 3, 4];
console.log(array1.reduce((accumulator, currentValue) => accumulator + currentValue)); // expected output: 10
```
You can also define the argument to the reduce method as a variable or constant and hand that in to the function, e.g.,
```
const array1 = [1, 2, 3, 4];
const reducer = (accumulator, currentValue) => accumulator + currentValue;
// 1 + 2 + 3 + 4
console.log(array1.reduce(reducer)); // expected output: 10
// 5 + 1 + 2 + 3 + 4
console.log(array1.reduce(reducer, 5)); // expected output: 15
```
You can see and run this code at [Array.prototype.reduce()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce).
## Solution:
```javascript
let myArray = [1, 2, 3];
let arraySum = myArray.reduce((previous, current) => previous + current);
console.log(`Sum of array values is: ${arraySum}`);
```

View File

@ -0,0 +1,22 @@
---
title: Catch Use of Assignment Operator Instead of Equality Operator
---
## Catch Use of Assignment Operator Instead of Equality Operator
- Only the if statement must be editied in this challenege.
- The `=` operator on its own is only used to assign values, not to compare them.
## Solution
```javascript
let x = 7;
let y = 9;
let result = "to come";
if(x == y) {
result = "Equal!";
} else {
result = "Not equal!";
}
console.log(result);
```

View File

@ -0,0 +1,13 @@
---
title: Debugging
---
## Debugging
This is a stub. <a href='https://github.com/freecodecamp/guides/tree/master/src/pages/mathematics/quadratic-equations/index.md' target='_blank' rel='nofollow'>Help our community expand it</a>.
<a href='https://github.com/freecodecamp/guides/blob/master/README.md' target='_blank' rel='nofollow'>This quick style guide will help ensure your pull request gets accepted</a>.
<!-- The article goes here, in GitHub-flavored Markdown. Feel free to add YouTube videos, images, and CodePen/JSBin embeds -->
#### More Information:
<!-- Please add any articles you think might be helpful to read before writing the article -->

View File

@ -0,0 +1,26 @@
---
title: Prevent Infinite Loops with a Valid Terminal Condition
---
## Prevent Infinite Loops with a Valid Terminal Condition
- To prevent an infinite loop, the `while-condition` must reach a terminal condition to exit out of the loop.
- So the error in this challenge occurs due to the condition - `i != 4` - in the for loop.
- If you take a closer look at the code:
```javascript
function myFunc() {
for (let i = 1; i != 4; i += 2) {
console.log("Still going!");
}
}
```
- You will see that `i` is first initialised as 1 and after every iteration of the loop, `i` is incremented by 2.
- Using this logic, after the first iteration - `i = 3` and the second iteration `i = 5`, the condition `i != 4` will never be met and an infinite loop will occur.
## Solution:
```javascript
function myFunc() {
for (let i = 1; i <= 4; i += 2) {
console.log("Still going!");
}
}
```

View File

@ -0,0 +1,10 @@
---
title: Understanding the Differences between the freeCodeCamp and Browser Console
---
## Understanding the Differences between the freeCodeCamp and Browser Console
This is a stub. <a href='https://github.com/freecodecamp/guides/tree/master/src/pages/certifications/javascript-algorithms-and-data-structures/debugging/understanding-the-differences-between-the-freecodecamp-and-browser-console/index.md' target='_blank' rel='nofollow'>Help our community expand it</a>.
<a href='https://github.com/freecodecamp/guides/blob/master/README.md' target='_blank' rel='nofollow'>This quick style guide will help ensure your pull request gets accepted</a>.
<!-- The article goes here, in GitHub-flavored Markdown. Feel free to add YouTube videos, images, and CodePen/JSBin embeds -->

View File

@ -0,0 +1,44 @@
---
title: Use Caution When Reinitializing Variables Inside a Loop
---
## Use Caution When Reinitializing Variables Inside a Loop
- This challenge must be solved by redefining the scope of `row[]`.
- Below is an example of the desired matrix.
```javascript
[
[0][0],
[0][0],
[0][0]
]
```
- However the current matrix - seen below - is far from the desired matrix
```javascript
[
[0][0][0][0][0][0],
[0][0][0][0][0][0],
[0][0][0][0][0][0]
]
```
- This error occurs due to the `row[]` array being declared as a global variable outside of the nested for loop.
- However, to fill the matrix correctly the `row[]` array must be reset after each iteration of the outer loop.
## Solution
```javascript
function zeroArray(m, n) {
let newArray = [];
for (let i = 0; i < m; i++) {
let row = []; /* <----- row has been declared inside the outer loop.
Now a new row will be initialised during each iteration of the outer loop allowing
for the desired matrix. */
for (let j = 0; j < n; j++) {
row.push(0);
}
newArray.push(row);
}
return newArray;
}
let matrix = zeroArray(3, 2);
console.log(matrix);
```

View File

@ -0,0 +1,10 @@
---
title: Use the JavaScript Console to Check the Value of a Variable
---
## Use the JavaScript Console to Check the Value of a Variable
This is a stub. <a href='https://github.com/freecodecamp/guides/tree/master/src/pages/certifications/javascript-algorithms-and-data-structures/debugging/use-the-javascript-console-to-check-the-value-of-a-variable/index.md' target='_blank' rel='nofollow'>Help our community expand it</a>.
<a href='https://github.com/freecodecamp/guides/blob/master/README.md' target='_blank' rel='nofollow'>This quick style guide will help ensure your pull request gets accepted</a>.
<!-- The article goes here, in GitHub-flavored Markdown. Feel free to add YouTube videos, images, and CodePen/JSBin embeds -->

View File

@ -0,0 +1,12 @@
---
title: Use typeof to Check the Type of a Variable
---
## Use typeof to Check the Type of a Variable
- Use `console.log(typeof variable)` to display the type of the desired variable.
## Solution:
```javascript
console.log(typeof seven);
console.log(typeof three);
```