chore(learn): audit javascript algorithms and data structures (#41092)
* chore(learn): audit basic algorithm scripting * chore(learn): audit basic data structures * chore(learn): audit basic javascript * chore(learn): audit debugging * chore(learn): audit es6 * chore(learn): audit functional programming * chore(learn): audit intermidate algorithms * chore(learn): audit js projects * chore(learn): audit object oriented programming * chore(learn): audit regex * fix(learn): remove stray . * fix(learn): string to code * fix(learn): missed some * fix(learn): clarify strings Based on Randy's feedback, clarifies string instances where quotes were removed in favour of back ticks. * fix: apply suggestions - thanks Randy! :) Co-authored-by: Randell Dawson <5313213+RandellDawson@users.noreply.github.com> * fix: non-suggestion comments * chore(learn): remove comments from codes Removes the comments from the description and instruction code blocks to ensure that all relevant information is translatable. * fix: Apply suggestions from code review Co-authored-by: Shaun Hamilton <51722130+ShaunSHamilton@users.noreply.github.com> * fix: revert crowdin fix * Update curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-algorithm-scripting/mutations.md Co-authored-by: Randell Dawson <5313213+RandellDawson@users.noreply.github.com> * fix: Apply suggestions from code review Co-authored-by: Shaun Hamilton <51722130+ShaunSHamilton@users.noreply.github.com> * Update curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/use-destructuring-assignment-to-assign-variables-from-arrays.md Co-authored-by: Shaun Hamilton <51722130+ShaunSHamilton@users.noreply.github.com> * fix: Apply suggestions from code review Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> Co-authored-by: Shaun Hamilton <51722130+ShaunSHamilton@users.noreply.github.com> * chore: change voice * fix: Christopher Nolan * fix: expressions would evaluate * fix: will -> would * Update curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/add-methods-after-inheritance.md Co-authored-by: Randell Dawson <5313213+RandellDawson@users.noreply.github.com> * fix: to work to push * Update curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/iterate-with-javascript-for-loops.md Co-authored-by: Shaun Hamilton <51722130+ShaunSHamilton@users.noreply.github.com> * Update curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/add-methods-after-inheritance.md Co-authored-by: Randell Dawson <5313213+RandellDawson@users.noreply.github.com> Co-authored-by: Randell Dawson <5313213+RandellDawson@users.noreply.github.com> Co-authored-by: Shaun Hamilton <51722130+ShaunSHamilton@users.noreply.github.com> Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
This commit is contained in:
committed by
GitHub
parent
57f3c80345
commit
7117919d36
@ -16,10 +16,12 @@ The variables in the following example are different:
|
||||
function myFunction() {
|
||||
return "You rock!";
|
||||
}
|
||||
let varOne = myFunction; // set to equal a function
|
||||
let varTwo = myFunction(); // set to equal the string "You rock!"
|
||||
let varOne = myFunction;
|
||||
let varTwo = myFunction();
|
||||
```
|
||||
|
||||
Here `varOne` is the function `myFunction`, and `varTwo` is the string `You rock!`.
|
||||
|
||||
# --instructions--
|
||||
|
||||
Fix the code so the variable `result` is set to the value returned from calling the function `getNine`.
|
||||
|
@ -15,17 +15,16 @@ Having two choices is great when a string has contractions or another piece of t
|
||||
Here are some examples of mixing quotes:
|
||||
|
||||
```js
|
||||
// These are correct:
|
||||
const grouchoContraction = "I've had a perfectly wonderful evening, but this wasn't it.";
|
||||
const quoteInString = "Groucho Marx once said 'Quote me as saying I was mis-quoted.'";
|
||||
// This is incorrect:
|
||||
const uhOhGroucho = 'I've had a perfectly wonderful evening, but this wasn't it.';
|
||||
```
|
||||
|
||||
The first two are correct, but the third is incorrect.
|
||||
|
||||
Of course, it is okay to use only one style of quotes. You can escape the quotes inside the string by using the backslash (<code>\\</code>) escape character:
|
||||
|
||||
```js
|
||||
// Correct use of same quotes:
|
||||
const allSameQuotes = 'I\'ve had a perfectly wonderful evening, but this wasn\'t it.';
|
||||
```
|
||||
|
||||
@ -35,7 +34,7 @@ Fix the string so it either uses different quotes for the `href` value, or escap
|
||||
|
||||
# --hints--
|
||||
|
||||
Your code should fix the quotes around the `href` value "#Home" by either changing or escaping them.
|
||||
Your code should fix the quotes around the `href` value `#Home` by either changing or escaping them.
|
||||
|
||||
```js
|
||||
assert(code.match(/<a href=\s*?('|\\")#Home\1\s*?>/g));
|
||||
|
@ -16,19 +16,18 @@ When you use string or array methods that take index ranges as arguments, it hel
|
||||
let alphabet = "abcdefghijklmnopqrstuvwxyz";
|
||||
let len = alphabet.length;
|
||||
for (let i = 0; i <= len; i++) {
|
||||
// loops one too many times at the end
|
||||
console.log(alphabet[i]);
|
||||
}
|
||||
for (let j = 1; j < len; j++) {
|
||||
// loops one too few times and misses the first character at index 0
|
||||
console.log(alphabet[j]);
|
||||
}
|
||||
for (let k = 0; k < len; k++) {
|
||||
// Goldilocks approves - this is just right
|
||||
console.log(alphabet[k]);
|
||||
}
|
||||
```
|
||||
|
||||
The first example here loops one too many times, and the second loops one too few times (missing the first index, 0). The third example is correct.
|
||||
|
||||
# --instructions--
|
||||
|
||||
Fix the two indexing errors in the following function so all the numbers 1 through 5 are printed to the console.
|
||||
|
@ -24,7 +24,7 @@ Your code should fix the missing piece of the array.
|
||||
assert(code.match(/myArray\s*?=\s*?\[\s*?1\s*?,\s*?2\s*?,\s*?3\s*?\];/g));
|
||||
```
|
||||
|
||||
Your code should fix the missing piece of the `.reduce()` method. The console output should show that "Sum of array values is: 6".
|
||||
Your code should fix the missing piece of the `.reduce()` method. The console output should show that `Sum of array values is: 6`.
|
||||
|
||||
```js
|
||||
assert(arraySum === 6);
|
||||
|
@ -20,12 +20,14 @@ The code below assigns `x` to be 2, which evaluates as `true`. Almost every valu
|
||||
let x = 1;
|
||||
let y = 2;
|
||||
if (x = y) {
|
||||
// this code block will run for any value of y (unless y were originally set as a falsy)
|
||||
|
||||
} else {
|
||||
// this code block is what should run (but won't) in this example
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
In this example, the code block within the `if` statement will run for any value of `y`, unless `y` is falsy. The `else` block, which we expect to run here, will not actually run.
|
||||
|
||||
# --instructions--
|
||||
|
||||
Fix the condition so the program runs the right branch, and the appropriate value is assigned to `result`.
|
||||
|
@ -20,7 +20,7 @@ The freeCodeCamp console is cleared before the tests are run and, to avoid spam,
|
||||
|
||||
If you would like to see every log for every test, run the tests, and open the browser console. If you prefer to use the browser console, and want it to mimic the freeCodeCamp console, place `console.clear()` before any other `console` calls, to clear the browser console.
|
||||
|
||||
**Note:** `console.log`s inside functions are printed to the freeCodeCamp console whenever those functions are called, this can help debugging functions that are called during testing.
|
||||
**Note:** `console.log`s inside functions are printed to the freeCodeCamp console whenever those functions are called. This can help debugging functions that are called during testing.
|
||||
|
||||
# --instructions--
|
||||
|
||||
|
@ -14,7 +14,7 @@ You can find Developer tools in your Chrome's menu or Web Console in Firefox's m
|
||||
|
||||
The `console.log()` method, which "prints" the output of what's within its parentheses to the console, will likely be the most helpful debugging tool. Placing it at strategic points in your code can show you the intermediate values of variables. It's good practice to have an idea of what the output should be before looking at what it is. Having check points to see the status of your calculations throughout your code will help narrow down where the problem is.
|
||||
|
||||
Here's an example to print 'Hello world!' to the console:
|
||||
Here's an example to print the string `Hello world!` to the console:
|
||||
|
||||
`console.log('Hello world!');`
|
||||
|
||||
|
@ -13,12 +13,14 @@ You can use `typeof` to check the data structure, or type, of a variable. This i
|
||||
Here are some examples using `typeof`:
|
||||
|
||||
```js
|
||||
console.log(typeof ""); // outputs "string"
|
||||
console.log(typeof 0); // outputs "number"
|
||||
console.log(typeof []); // outputs "object"
|
||||
console.log(typeof {}); // outputs "object"
|
||||
console.log(typeof "");
|
||||
console.log(typeof 0);
|
||||
console.log(typeof []);
|
||||
console.log(typeof {});
|
||||
```
|
||||
|
||||
In order, the console will display the strings `string`, `number`, `object`, and `object`.
|
||||
|
||||
JavaScript recognizes six primitive (immutable) data types: `Boolean`, `Null`, `Undefined`, `Number`, `String`, and `Symbol` (new with ES6) and one type for mutable items: `Object`. Note that in JavaScript, arrays are technically a type of object.
|
||||
|
||||
# --instructions--
|
||||
|
Reference in New Issue
Block a user