fix(guide): restructure curriculum guide articles (#36501)

* fix: restructure certifications guide articles
* fix: added 3 dashes line before prob expl
* fix: added 3 dashes line before hints
* fix: added 3 dashes line before solutions
This commit is contained in:
Randell Dawson
2019-07-24 00:59:27 -07:00
committed by mrugesh
parent c911e77eed
commit 1494a50123
990 changed files with 13202 additions and 8628 deletions

View File

@@ -1,7 +1,10 @@
---
title: Catch Arguments Passed in the Wrong Order When Calling a Function
---
## Catch Arguments Passed in the Wrong Order When Calling a Function
# Catch Arguments Passed in the Wrong Order When Calling a Function
---
## Problem Explanation
```javascript
function raiseToPower(b, e) {
@@ -13,7 +16,21 @@ function raiseToPower(b, 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 the variable `power` is implementing the `raiseToPower` function correctly.
## Solution:
---
## Solutions
<details><summary>Solution 1 (Click to Show/Hide)</summary>
```javascript
function raiseToPower(b, e) {
return Math.pow(b, e);
}
let base = 2;
let exp = 3;
let power = raiseToPower(base, exp);
console.log(power);
```
</details>

View File

@@ -1,12 +1,30 @@
---
title: Catch Missing Open and Closing Parenthesis After a Function Call
---
## Catch Missing Open and Closing Parenthesis After a Function Call
# Catch Missing Open and Closing Parenthesis After a Function Call
---
## Hints
### Hint 1
- Remember to add opening and closing parentheses when calling a function.
- FunctionName + ();
## Solution:
---
## Solutions
<details><summary>Solution 1 (Click to Show/Hide)</summary>
```javascript
let result = getNine();
function getNine() {
let x = 6;
let y = 3;
return x + y;
}
let result = getNine();
console.log(result);
```
</details>

View File

@@ -1,12 +1,13 @@
---
title: Catch Misspelled Variable and Function Names
---
## 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
---
## Hints
### Hint 1
Check the spelling of the first two variables against when it is used. Also, reading a text backwards can help with detecting spelling errors. Make sure to check for these common spelling mistakes in English:
* vowel confusion (a instead of e, i instead of a)
@@ -14,9 +15,11 @@ Check the spelling of the first two variables against when it is used. Also, rea
* ous vs os
* double letters if certain one-syllable words adding a suffix (like "big" to "bigger")
## Spoiler alert!
**Solution ahead!**
---
## Solutions
<details><summary>Solution 1 (Click to Show/Hide)</summary>
```javascript
// 'i' and 'e' swapped in "receivables" and missing 's' in "payables"
@@ -27,3 +30,4 @@ let netWorkingCapital = receivables - payables;
console.log(`Net working capital is: ${netWorkingCapital}`);
```
</details>

View File

@@ -1,14 +1,27 @@
---
title: Catch Mixed Usage of Single and Double Quotes
---
## 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:
---
## Hints
### Hint 1
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.
### Hint 2
The test cases will only be passed by using double quotes.
---
## Solutions
<details><summary>Solution 1 (Click to Show/Hide)</summary>
```javascript
//Solution1:
let innerHtml = "<p>Click here to <a href=\"#Home\">return home</a></p>";
let innerHtml = '<p>Click here to <a href="#Home">return home</a></p>';
console.log(innerHtml);
```
</details>

View File

@@ -1,9 +1,10 @@
---
title: Catch Off By One Errors When Using Indexing
---
## Catch Off By One Errors When Using Indexing
# Catch Off By One Errors When Using Indexing
### Basics
---
## Problem Explanation
Due to the way JavaScript indexes work `firstFive` has **five elements** but they are indexed from **0 to 4**!
```javascript
@@ -15,23 +16,23 @@ 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
**Debugging**
You are given this code:
```javascript
for (let i = 1; i <= len; i++) {
console.log(firstFive[i]);
}
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.clear();
for (let i = 1; i <= len; i++) {
console.log(firstFive[i]);
}
```
Console output:
```text
```
Console was cleared.
2
3
@@ -39,17 +40,35 @@ Console output:
5
undefined
```
### Analysis
**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!).
---
## Solutions
<details><summary>Solution 1 (Click to Show/Hide)</summary>
```javascript
function countToFive() {
let firstFive = "12345";
let len = firstFive.length;
// Fix the line below
for (let i = 0; i < len; i++) {
// Do not alter code below this line
console.log(firstFive[i]);
}
}
```
**Happy Coding!**
### Resources
#### Code Explanation
* 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!).
#### Relevant Links
- [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)
</details>

View File

@@ -1,8 +1,10 @@
---
title: Catch Unclosed Parentheses, Brackets, Braces and Quotes
---
## Catch Unclosed Parentheses, Brackets, Braces and Quotes
# Catch Unclosed Parentheses, Brackets, Braces and Quotes
---
## Problem Explanation
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:
```
@@ -24,10 +26,16 @@ 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:
---
## Solutions
<details><summary>Solution 1 (Click to Show/Hide)</summary>
```javascript
let myArray = [1, 2, 3];
let arraySum = myArray.reduce((previous, current) => previous + current);
console.log(`Sum of array values is: ${arraySum}`);
```
</details>

View File

@@ -1,18 +1,30 @@
---
title: Catch Use of Assignment Operator Instead of Equality Operator
---
## 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
---
## Hints
### Hint 1
Only the if statement must be editied in this challenege.
### Hint 2
The `=` operator on its own is only used to assign values, not to compare them.
---
## Solutions
<details><summary>Solution 1 (Click to Show/Hide)</summary>
```javascript
let x = 7;
let y = 9;
let result = "to come";
if(x == y) {
if (x == y) {
result = "Equal!";
} else {
result = "Not equal!";
@@ -20,3 +32,4 @@ if(x == y) {
console.log(result);
```
</details>

View File

@@ -1,13 +1,11 @@
---
title: Debugging
---
## 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

@@ -1,11 +1,14 @@
---
title: Prevent Infinite Loops with a Valid Terminal Condition
---
## Prevent Infinite Loops with a Valid Terminal Condition
# Prevent Infinite Loops with a Valid Terminal Condition
---
## Problem Explanation
- 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) {
@@ -16,7 +19,12 @@ function myFunc() {
- 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:
---
## Solutions
<details><summary>Solution 1 (Click to Show/Hide)</summary>
```javascript
function myFunc() {
for (let i = 1; i <= 4; i += 2) {
@@ -24,3 +32,4 @@ function myFunc() {
}
}
```
</details>

View File

@@ -1,9 +1,13 @@
---
title: Understanding the Differences between the freeCodeCamp and Browser Console
---
## Understanding the Differences between the freeCodeCamp and Browser Console
# Understanding the Differences between the freeCodeCamp and Browser Console
#### Hint:
---
## Hints
### Hint 1
So were exactly do you run this *console.log()* command?
In order to see the difference between the live console (terminal of freecodecamp) and our browser console we need to open up the console in our browser.
Contemporary internet browser have a built in feature called Developer Tools which, among others contains a live console.
@@ -30,9 +34,12 @@ Lastly, click: Develop->Show Error Console
* Click the the following: ''...'' symbol->Developer Tools-> Console tab
---
## Solutions
#### Solution:
``` javascript
<details><summary>Solution 1 (Click to Show/Hide)</summary>
```javascript
// Open your browser console
let outputTwo = "This will print to the browser console 2 times";
// Use console.log() to print the outputTwo variable
@@ -46,3 +53,5 @@ console.clear();
// Use console.log() to print the outputOne variable
console.log(outputOne);
```
</details>

View File

@@ -1,38 +1,36 @@
---
title: Use Caution When Reinitializing Variables Inside a Loop
---
## Use Caution When Reinitializing Variables Inside a Loop
# Use Caution When Reinitializing Variables Inside a Loop
---
## Problem Explanation
- 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]
]
[[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]
]
[[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
---
## Solutions
<details><summary>Solution 1 (Click to Show/Hide)</summary>
```javascript
function zeroArray(m, n) {
let newArray = [];
for (let i = 0; i < m; i++) {
let row = []; /* <----- row has been declared inside the outer loop.
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);
@@ -42,3 +40,5 @@ function zeroArray(m, n) {
let matrix = zeroArray(3, 2);
console.log(matrix);
```
</details>

View File

@@ -1,9 +1,13 @@
---
title: Use the JavaScript Console to Check the Value of a Variable
---
## Use the JavaScript Console to Check the Value of a Variable
# Use the JavaScript Console to Check the Value of a Variable
### Solution
<details><summary>Solution 1 (Click to Show/Hide)</summary>
---
## Solutions
```js
let a = 5;
@@ -16,3 +20,5 @@ console.log(sumAB);
console.log(a);
```
</details>

View File

@@ -1,12 +1,24 @@
---
title: Use typeof to Check the Type of a Variable
---
## 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:
---
## Hints
### Hint 1
Use `console.log(typeof variable)` to display the type of the desired variable.
---
## Solutions
<details><summary>Solution 1 (Click to Show/Hide)</summary>
```javascript
console.log(typeof seven);
console.log(typeof three);
```
</details>