Feat: add new Markdown parser (#39800)

and change all the challenges to new `md` format.
This commit is contained in:
Oliver Eyton-Williams
2020-11-27 19:02:05 +01:00
committed by GitHub
parent a07f84c8ec
commit 0bd52f8bd1
2580 changed files with 113436 additions and 111979 deletions

View File

@ -5,34 +5,31 @@ challengeType: 1
forumTopicId: 301184
---
## Description
<section id='description'>
# --description--
Continuing the discussion on calling functions, the next bug to watch out for is when a function's arguments are supplied in the incorrect order. If the arguments are different types, such as a function expecting an array and an integer, this will likely throw a runtime error. If the arguments are the same type (all integers, for example), then the logic of the code won't make sense. Make sure to supply all required arguments, in the proper order to avoid these issues.
</section>
## Instructions
<section id='instructions'>
The function <code>raiseToPower</code> raises a base to an exponent. Unfortunately, it's not called properly - fix the code so the value of <code>power</code> is the expected 8.
</section>
# --instructions--
## Tests
<section id='tests'>
The function `raiseToPower` raises a base to an exponent. Unfortunately, it's not called properly - fix the code so the value of `power` is the expected 8.
```yml
tests:
- text: Your code should fix the variable <code>power</code> so it equals 2 raised to the 3rd power, not 3 raised to the 2nd power.
testString: assert(power == 8);
- text: Your code should use the correct order of the arguments for the <code>raiseToPower</code> function call.
testString: assert(code.match(/raiseToPower\(\s*?base\s*?,\s*?exp\s*?\);/g));
# --hints--
Your code should fix the variable `power` so it equals 2 raised to the 3rd power, not 3 raised to the 2nd power.
```js
assert(power == 8);
```
</section>
Your code should use the correct order of the arguments for the `raiseToPower` function call.
## Challenge Seed
<section id='challengeSeed'>
```js
assert(code.match(/raiseToPower\(\s*?base\s*?,\s*?exp\s*?\);/g));
```
<div id='js-seed'>
# --seed--
## --seed-contents--
```js
function raiseToPower(b, e) {
@ -45,14 +42,7 @@ let power = raiseToPower(exp, base);
console.log(power);
```
</div>
</section>
## Solution
<section id='solution'>
# --solutions--
```js
function raiseToPower(b, e) {
@ -64,5 +54,3 @@ let exp = 3;
let power = raiseToPower(base, exp);
console.log(power);
```
</section>

View File

@ -5,9 +5,10 @@ challengeType: 1
forumTopicId: 301185
---
## Description
<section id='description'>
# --description--
When a function or method doesn't take any arguments, you may forget to include the (empty) opening and closing parentheses when calling it. Often times the result of a function call is saved in a variable for other use in your code. This error can be detected by logging variable values (or their types) to the console and seeing that one is set to a function reference, instead of the expected value the function returns.
The variables in the following example are different:
```js
@ -18,31 +19,27 @@ let varOne = myFunction; // set to equal a function
let varTwo = myFunction(); // set to equal the string "You rock!"
```
</section>
# --instructions--
## Instructions
<section id='instructions'>
Fix the code so the variable <code>result</code> is set to the value returned from calling the function <code>getNine</code>.
</section>
Fix the code so the variable `result` is set to the value returned from calling the function `getNine`.
## Tests
<section id='tests'>
# --hints--
```yml
tests:
- text: Your code should fix the variable <code>result</code> so it is set to the number that the function <code>getNine</code> returns.
testString: assert(result == 9);
- text: Your code should call the <code>getNine</code> function.
testString: assert(code.match(/getNine\(\)/g).length == 2);
Your code should fix the variable `result` so it is set to the number that the function `getNine` returns.
```js
assert(result == 9);
```
</section>
Your code should call the `getNine` function.
## Challenge Seed
<section id='challengeSeed'>
```js
assert(code.match(/getNine\(\)/g).length == 2);
```
<div id='js-seed'>
# --seed--
## --seed-contents--
```js
function getNine() {
@ -55,14 +52,7 @@ let result = getNine;
console.log(result);
```
</div>
</section>
## Solution
<section id='solution'>
# --solutions--
```js
function getNine() {
@ -74,5 +64,3 @@ function getNine() {
let result = getNine();
console.log(result);
```
</section>

View File

@ -5,41 +5,51 @@ challengeType: 1
forumTopicId: 301186
---
## Description
<section id='description'>
The <code>console.log()</code> and <code>typeof</code> methods are the two primary ways to check intermediate values and types of program output. Now it's time to get into the common forms that bugs take. One syntax-level issue that fast typers can commiserate with is the humble spelling error.
# --description--
The `console.log()` and `typeof` methods are the two primary ways to check intermediate values and types of program output. Now it's time to get into the common forms that bugs take. One syntax-level issue that fast typers can commiserate with is the humble spelling error.
Transposed, missing, or mis-capitalized characters in a variable or function name will have the browser looking for an object that doesn't exist - and complain in the form of a reference error. JavaScript variable and function names are case-sensitive.
</section>
## Instructions
<section id='instructions'>
Fix the two spelling errors in the code so the <code>netWorkingCapital</code> calculation works.
</section>
# --instructions--
## Tests
<section id='tests'>
Fix the two spelling errors in the code so the `netWorkingCapital` calculation works.
```yml
tests:
- text: 'Check the spelling of the two variables used in the netWorkingCapital calculation, the console output should show that "Net working capital is: 2".'
testString: 'assert(netWorkingCapital === 2);'
- text: There should be no instances of mis-spelled variables in the code.
testString: assert(!code.match(/recievables/g));
- text: The <code>receivables</code> variable should be declared and used properly in the code.
testString: assert(code.match(/receivables/g).length == 2);
- text: There should be no instances of mis-spelled variables in the code.
testString: assert(!code.match(/payable;/g));
- text: The <code>payables</code> variable should be declared and used properly in the code.
testString: assert(code.match(/payables/g).length == 2);
# --hints--
Check the spelling of the two variables used in the netWorkingCapital calculation, the console output should show that "Net working capital is: 2".
```js
assert(netWorkingCapital === 2);
```
</section>
There should be no instances of mis-spelled variables in the code.
## Challenge Seed
<section id='challengeSeed'>
```js
assert(!code.match(/recievables/g));
```
<div id='js-seed'>
The `receivables` variable should be declared and used properly in the code.
```js
assert(code.match(/receivables/g).length == 2);
```
There should be no instances of mis-spelled variables in the code.
```js
assert(!code.match(/payable;/g));
```
The `payables` variable should be declared and used properly in the code.
```js
assert(code.match(/payables/g).length == 2);
```
# --seed--
## --seed-contents--
```js
let receivables = 10;
@ -48,14 +58,7 @@ let netWorkingCapital = recievables - payable;
console.log(`Net working capital is: ${netWorkingCapital}`);
```
</div>
</section>
## Solution
<section id='solution'>
# --solutions--
```js
let receivables = 10;
@ -63,5 +66,3 @@ let payables = 8;
let netWorkingCapital = receivables - payables;
console.log(`Net working capital is: ${netWorkingCapital}`);
```
</section>

View File

@ -5,10 +5,12 @@ challengeType: 1
forumTopicId: 301188
---
## Description
<section id='description'>
JavaScript allows the use of both single (<code>'</code>) and double (<code>"</code>) quotes to declare a string. Deciding which one to use generally comes down to personal preference, with some exceptions.
# --description--
JavaScript allows the use of both single (`'`) and double (`"`) quotes to declare a string. Deciding which one to use generally comes down to personal preference, with some exceptions.
Having two choices is great when a string has contractions or another piece of text that's in quotes. Just be careful that you don't close the string too early, which causes a syntax error.
Here are some examples of mixing quotes:
```js
@ -19,56 +21,43 @@ const quoteInString = "Groucho Marx once said 'Quote me as saying I was mis-quot
const uhOhGroucho = 'I've had a perfectly wonderful evening, but this wasn't it.';
```
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:
Of course, it is okay to use only one style of quotes. You can escape the quotes inside the string by using the backslash (`\`) escape character:
```js
// Correct use of same quotes:
const allSameQuotes = 'I\'ve had a perfectly wonderful evening, but this wasn\'t it.';
```
</section>
# --instructions--
## Instructions
<section id='instructions'>
Fix the string so it either uses different quotes for the <code>href</code> value, or escape the existing ones. Keep the double quote marks around the entire string.
</section>
Fix the string so it either uses different quotes for the `href` value, or escape the existing ones. Keep the double quote marks around the entire string.
## Tests
<section id='tests'>
# --hints--
```yml
tests:
- text: Your code should fix the quotes around the <code>href</code> value "#Home" by either changing or escaping them.
testString: assert(code.match(/<a href=\s*?('|\\")#Home\1\s*?>/g));
- text: Your code should keep the double quotes around the entire string.
testString: assert(code.match(/"<p>.*?<\/p>";/g));
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));
```
</section>
Your code should keep the double quotes around the entire string.
## Challenge Seed
<section id='challengeSeed'>
```js
assert(code.match(/"<p>.*?<\/p>";/g));
```
<div id='js-seed'>
# --seed--
## --seed-contents--
```js
let innerHtml = "<p>Click here to <a href="#Home">return home</a></p>";
console.log(innerHtml);
```
</div>
</section>
## Solution
<section id='solution'>
# --solutions--
```js
let innerHtml = "<p>Click here to <a href=\"#Home\">return home</a></p>";
console.log(innerHtml);
```
</section>

View File

@ -5,9 +5,10 @@ challengeType: 1
forumTopicId: 301189
---
## Description
<section id='description'>
<dfn>Off by one errors</dfn> (sometimes called OBOE) crop up when you're trying to target a specific index of a string or array (to slice or access a segment), or when looping over the indices of them. JavaScript indexing starts at zero, not one, which means the last index is always one less than the length of the item. If you try to access an index equal to the length, the program may throw an "index out of range" reference error or print <code>undefined</code>.
# --description--
<dfn>Off by one errors</dfn> (sometimes called OBOE) crop up when you're trying to target a specific index of a string or array (to slice or access a segment), or when looping over the indices of them. JavaScript indexing starts at zero, not one, which means the last index is always one less than the length of the item. If you try to access an index equal to the length, the program may throw an "index out of range" reference error or print `undefined`.
When you use string or array methods that take index ranges as arguments, it helps to read the documentation and understand if they are inclusive (the item at the given index is part of what's returned) or not. Here are some examples of off by one errors:
```js
@ -27,35 +28,39 @@ for (let k = 0; k < len; k++) {
}
```
</section>
# --instructions--
## Instructions
<section id='instructions'>
Fix the two indexing errors in the following function so all the numbers 1 through 5 are printed to the console.
</section>
## Tests
<section id='tests'>
# --hints--
```yml
tests:
- text: Your code should set the initial condition of the loop so it starts at the first index.
testString: assert(code.match(/i\s*?=\s*?0\s*?;/g).length == 1);
- text: Your code should fix the initial condition of the loop so that the index starts at 0.
testString: assert(!code.match(/i\s?=\s*?1\s*?;/g));
- text: Your code should set the terminal condition of the loop so it stops at the last index.
testString: assert(code.match(/i\s*?<\s*?len\s*?;/g).length == 1);
- text: Your code should fix the terminal condition of the loop so that it stops at 1 before the length.
testString: assert(!code.match(/i\s*?<=\s*?len;/g));
Your code should set the initial condition of the loop so it starts at the first index.
```js
assert(code.match(/i\s*?=\s*?0\s*?;/g).length == 1);
```
</section>
Your code should fix the initial condition of the loop so that the index starts at 0.
## Challenge Seed
<section id='challengeSeed'>
```js
assert(!code.match(/i\s?=\s*?1\s*?;/g));
```
<div id='js-seed'>
Your code should set the terminal condition of the loop so it stops at the last index.
```js
assert(code.match(/i\s*?<\s*?len\s*?;/g).length == 1);
```
Your code should fix the terminal condition of the loop so that it stops at 1 before the length.
```js
assert(!code.match(/i\s*?<=\s*?len;/g));
```
# --seed--
## --seed-contents--
```js
function countToFive() {
@ -71,14 +76,7 @@ function countToFive() {
countToFive();
```
</div>
</section>
## Solution
<section id='solution'>
# --solutions--
```js
function countToFive() {
@ -93,5 +91,3 @@ function countToFive() {
countToFive();
```
</section>

View File

@ -5,35 +5,33 @@ challengeType: 1
forumTopicId: 301190
---
## Description
<section id='description'>
# --description--
Another syntax error to be aware of is that all opening parentheses, brackets, curly braces, and quotes have a closing pair. Forgetting a piece tends to happen when you're editing existing code and inserting items with one of the pair types. Also, take care when nesting code blocks into others, such as adding a callback function as an argument to a method.
One way to avoid this mistake is as soon as the opening character is typed, immediately include the closing match, then move the cursor back between them and continue coding. Fortunately, most modern code editors generate the second half of the pair automatically.
</section>
## Instructions
<section id='instructions'>
# --instructions--
Fix the two pair errors in the code.
</section>
## Tests
<section id='tests'>
# --hints--
```yml
tests:
- text: Your code should fix the missing piece of the array.
testString: assert(code.match(/myArray\s*?=\s*?\[\s*?1\s*?,\s*?2\s*?,\s*?3\s*?\];/g));
- text: 'Your code should fix the missing piece of the <code>.reduce()</code> method. The console output should show that "Sum of array values is: 6".'
testString: 'assert(arraySum === 6);'
Your code should fix the missing piece of the array.
```js
assert(code.match(/myArray\s*?=\s*?\[\s*?1\s*?,\s*?2\s*?,\s*?3\s*?\];/g));
```
</section>
Your code should fix the missing piece of the `.reduce()` method. The console output should show that "Sum of array values is: 6".
## Challenge Seed
<section id='challengeSeed'>
```js
assert(arraySum === 6);
```
<div id='js-seed'>
# --seed--
## --seed-contents--
```js
let myArray = [1, 2, 3;
@ -41,19 +39,10 @@ let arraySum = myArray.reduce((previous, current => previous + current);
console.log(`Sum of array values is: ${arraySum}`);
```
</div>
</section>
## Solution
<section id='solution'>
# --solutions--
```js
let myArray = [1, 2, 3];
let arraySum = myArray.reduce((previous, current) => previous + current);
console.log(`Sum of array values is: ${arraySum}`);
```
</section>

View File

@ -5,12 +5,15 @@ challengeType: 1
forumTopicId: 301191
---
## Description
<section id='description'>
Branching programs, i.e. ones that do different things if certain conditions are met, rely on <code>if</code>, <code>else if</code>, and <code>else</code> statements in JavaScript. The condition sometimes takes the form of testing whether a result is equal to a value.
This logic is spoken (in English, at least) as "if x equals y, then ..." which can literally translate into code using the <code>=</code>, or assignment operator. This leads to unexpected control flow in your program.
As covered in previous challenges, the assignment operator (<code>=</code>) in JavaScript assigns a value to a variable name. And the <code>==</code> and <code>===</code> operators check for equality (the triple <code>===</code> tests for strict equality, meaning both value and type are the same).
The code below assigns <code>x</code> to be 2, which evaluates as <code>true</code>. Almost every value on its own in JavaScript evaluates to <code>true</code>, except what are known as the "falsy" values: <code>false</code>, <code>0</code>, <code>""</code> (an empty string), <code>NaN</code>, <code>undefined</code>, and <code>null</code>.
# --description--
Branching programs, i.e. ones that do different things if certain conditions are met, rely on `if`, `else if`, and `else` statements in JavaScript. The condition sometimes takes the form of testing whether a result is equal to a value.
This logic is spoken (in English, at least) as "if x equals y, then ..." which can literally translate into code using the `=`, or assignment operator. This leads to unexpected control flow in your program.
As covered in previous challenges, the assignment operator (`=`) in JavaScript assigns a value to a variable name. And the `==` and `===` operators check for equality (the triple `===` tests for strict equality, meaning both value and type are the same).
The code below assigns `x` to be 2, which evaluates as `true`. Almost every value on its own in JavaScript evaluates to `true`, except what are known as the "falsy" values: `false`, `0`, `""` (an empty string), `NaN`, `undefined`, and `null`.
```js
let x = 1;
@ -22,31 +25,27 @@ if (x = y) {
}
```
</section>
# --instructions--
## Instructions
<section id='instructions'>
Fix the condition so the program runs the right branch, and the appropriate value is assigned to <code>result</code>.
</section>
Fix the condition so the program runs the right branch, and the appropriate value is assigned to `result`.
## Tests
<section id='tests'>
# --hints--
```yml
tests:
- text: Your code should fix the condition so it checks for equality, instead of using assignment.
testString: assert(result == "Not equal!");
- text: The condition should use either <code>==</code> or <code>===</code> to test for equality.
testString: assert(code.match(/x\s*?===?\s*?y/g));
Your code should fix the condition so it checks for equality, instead of using assignment.
```js
assert(result == 'Not equal!');
```
</section>
The condition should use either `==` or `===` to test for equality.
## Challenge Seed
<section id='challengeSeed'>
```js
assert(code.match(/x\s*?===?\s*?y/g));
```
<div id='js-seed'>
# --seed--
## --seed-contents--
```js
let x = 7;
@ -62,14 +61,7 @@ if(x = y) {
console.log(result);
```
</div>
</section>
## Solution
<section id='solution'>
# --solutions--
```js
let x = 7;
@ -84,5 +76,3 @@ if(x === y) {
console.log(result);
```
</section>

View File

@ -5,10 +5,11 @@ challengeType: 1
forumTopicId: 301192
---
## Description
<section id='description'>
# --description--
The final topic is the dreaded infinite loop. Loops are great tools when you need your program to run a code block a certain number of times or until a condition is met, but they need a terminal condition that ends the looping. Infinite loops are likely to freeze or crash the browser, and cause general program execution mayhem, which no one wants.
There was an example of an infinite loop in the introduction to this section - it had no terminal condition to break out of the <code>while</code> loop inside <code>loopy()</code>. Do NOT call this function!
There was an example of an infinite loop in the introduction to this section - it had no terminal condition to break out of the `while` loop inside `loopy()`. Do NOT call this function!
```js
function loopy() {
@ -19,31 +20,28 @@ function loopy() {
```
It's the programmer's job to ensure that the terminal condition, which tells the program when to break out of the loop code, is eventually reached. One error is incrementing or decrementing a counter variable in the wrong direction from the terminal condition. Another one is accidentally resetting a counter or index variable within the loop code, instead of incrementing or decrementing it.
</section>
## Instructions
<section id='instructions'>
The <code>myFunc()</code> function contains an infinite loop because the terminal condition <code>i != 4</code> will never evaluate to <code>false</code> (and break the looping) - <code>i</code> will increment by 2 each pass, and jump right over 4 since <code>i</code> is odd to start. Fix the comparison operator in the terminal condition so the loop only runs for <code>i</code> less than or equal to 4.
</section>
# --instructions--
## Tests
<section id='tests'>
The `myFunc()` function contains an infinite loop because the terminal condition `i != 4` will never evaluate to `false` (and break the looping) - `i` will increment by 2 each pass, and jump right over 4 since `i` is odd to start. Fix the comparison operator in the terminal condition so the loop only runs for `i` less than or equal to 4.
```yml
tests:
- text: Your code should change the comparison operator in the terminal condition (the middle part) of the <code>for</code> loop.
testString: assert(code.match(/i\s*?<=\s*?4;/g).length == 1);
- text: Your code should fix the comparison operator in the terminal condition of the loop.
testString: assert(!code.match(/i\s*?!=\s*?4;/g));
# --hints--
Your code should change the comparison operator in the terminal condition (the middle part) of the `for` loop.
```js
assert(code.match(/i\s*?<=\s*?4;/g).length == 1);
```
</section>
Your code should fix the comparison operator in the terminal condition of the loop.
## Challenge Seed
<section id='challengeSeed'>
```js
assert(!code.match(/i\s*?!=\s*?4;/g));
```
<div id='js-seed'>
# --seed--
## --seed-contents--
```js
function myFunc() {
@ -53,14 +51,7 @@ function myFunc() {
}
```
</div>
</section>
## Solution
<section id='solution'>
# --solutions--
```js
function myFunc() {
@ -69,5 +60,3 @@ function myFunc() {
}
}
```
</section>

View File

@ -5,41 +5,47 @@ challengeType: 1
forumTopicId: 301193
---
## Description
<section id='description'>
# --description--
You may have noticed that some freeCodeCamp JavaScript challenges include their own console. This console behaves a little differently than the browser console you used in the last challenge.
The following challenge is meant to highlight the main difference between the freeCodeCamp console and your browser console.
When you run ordinary JavaScript, the browser's console will display your <code>console.log()</code> statements the exact number of times it is called.
The freeCodeCamp console will print your <code>console.log()</code> statements a short time after the editor detects a change in the script, as well as during testing.
When you run ordinary JavaScript, the browser's console will display your `console.log()` statements the exact number of times it is called.
The freeCodeCamp console will print your `console.log()` statements a short time after the editor detects a change in the script, as well as during testing.
The freeCodeCamp console is cleared before the tests are run and, to avoid spam, only prints the logs during the first test (see the note below for exceptions).
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 <code>console.clear()</code> before any other <code>console</code> calls, to clear the browser console.
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.
</section>
## Instructions
<section id='instructions'>
First, use <code>console.log</code> to log the <code>output</code> variable. Then, use <code>console.clear</code> to clear the browser console.
</section>
# --instructions--
## Tests
<section id='tests'>
First, use `console.log` to log the `output` variable. Then, use `console.clear` to clear the browser console.
```yml
tests:
- text: You should use <code>console.clear()</code> to clear the browser console.
testString: assert(__helpers.removeWhiteSpace(__helpers.removeJSComments(code)).match(/console.clear\(\)/));
- text: You should use <code>console.log()</code> to print the <code>output</code> variable.
testString: assert(__helpers.removeWhiteSpace(code).match(/console\.log\(output\)/));
# --hints--
You should use `console.clear()` to clear the browser console.
```js
assert(
__helpers
.removeWhiteSpace(__helpers.removeJSComments(code))
.match(/console.clear\(\)/)
);
```
</section>
You should use `console.log()` to print the `output` variable.
## Challenge Seed
<section id='challengeSeed'>
```js
assert(__helpers.removeWhiteSpace(code).match(/console\.log\(output\)/));
```
<div id='js-seed'>
# --seed--
## --seed-contents--
```js
// Open your browser console.
@ -51,13 +57,7 @@ let output = "Get this to log once in the freeCodeCamp console and twice in the
// Now, add console.clear() before your console.log() to clear the browser console, and pass the tests.
```
</div>
</section>
## Solution
<section id='solution'>
# --solutions--
```js
// Open your browser console.
@ -70,5 +70,3 @@ console.log(output);
// Now, add console.clear() before your console.log() to clear the browser console, and pass the tests.
```
</section>

View File

@ -5,37 +5,41 @@ challengeType: 1
forumTopicId: 301194
---
## Description
<section id='description'>
# --description--
Sometimes it's necessary to save information, increment counters, or re-set variables within a loop. A potential issue is when variables either should be reinitialized, and aren't, or vice versa. This is particularly dangerous if you accidentally reset the variable being used for the terminal condition, causing an infinite loop.
Printing variable values with each cycle of your loop by using <code>console.log()</code> can uncover buggy behavior related to resetting, or failing to reset a variable.
</section>
## Instructions
<section id='instructions'>
The following function is supposed to create a two-dimensional array with <code>m</code> rows and <code>n</code> columns of zeroes. Unfortunately, it's not producing the expected output because the <code>row</code> variable isn't being reinitialized (set back to an empty array) in the outer loop. Fix the code so it returns a correct 3x2 array of zeroes, which looks like <code>[[0, 0], [0, 0], [0, 0]]</code>.
</section>
Printing variable values with each cycle of your loop by using `console.log()` can uncover buggy behavior related to resetting, or failing to reset a variable.
## Tests
<section id='tests'>
# --instructions--
```yml
tests:
- text: Your code should set the <code>matrix</code> variable to an array holding 3 rows of 2 columns of zeroes each.
testString: assert(JSON.stringify(matrix) == "[[0,0],[0,0],[0,0]]");
- text: The <code>matrix</code> variable should have 3 rows.
testString: assert(matrix.length == 3);
- text: The <code>matrix</code> variable should have 2 columns in each row.
testString: assert(matrix[0].length == 2 && matrix[1].length === 2 && matrix[2].length === 2);
The following function is supposed to create a two-dimensional array with `m` rows and `n` columns of zeroes. Unfortunately, it's not producing the expected output because the `row` variable isn't being reinitialized (set back to an empty array) in the outer loop. Fix the code so it returns a correct 3x2 array of zeroes, which looks like `[[0, 0], [0, 0], [0, 0]]`.
# --hints--
Your code should set the `matrix` variable to an array holding 3 rows of 2 columns of zeroes each.
```js
assert(JSON.stringify(matrix) == '[[0,0],[0,0],[0,0]]');
```
</section>
The `matrix` variable should have 3 rows.
## Challenge Seed
<section id='challengeSeed'>
```js
assert(matrix.length == 3);
```
<div id='js-seed'>
The `matrix` variable should have 2 columns in each row.
```js
assert(
matrix[0].length == 2 && matrix[1].length === 2 && matrix[2].length === 2
);
```
# --seed--
## --seed-contents--
```js
function zeroArray(m, n) {
@ -59,14 +63,7 @@ let matrix = zeroArray(3, 2);
console.log(matrix);
```
</div>
</section>
## Solution
<section id='solution'>
# --solutions--
```js
function zeroArray(m, n) {
@ -89,5 +86,3 @@ function zeroArray(m, n) {
let matrix = zeroArray(3, 2);
console.log(matrix);
```
</section>

View File

@ -5,36 +5,33 @@ challengeType: 1
forumTopicId: 18372
---
## Description
<section id='description'>
# --description--
Both Chrome and Firefox have excellent JavaScript consoles, also known as DevTools, for debugging your JavaScript.
You can find Developer tools in your Chrome's menu or Web Console in Firefox's menu. If you're using a different browser, or a mobile phone, we strongly recommend switching to desktop Firefox or Chrome.
The <code>console.log()</code> 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.
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:
<code>console.log('Hello world!');</code>
</section>
## Instructions
<section id='instructions'>
Use the <code>console.log()</code> method to print the value of the variable <code>a</code> where noted in the code.
</section>
`console.log('Hello world!');`
## Tests
<section id='tests'>
# --instructions--
```yml
tests:
- text: Your code should use <code>console.log()</code> to check the value of the variable <code>a</code>.
testString: assert(code.match(/console\.log\(a\)/g));
Use the `console.log()` method to print the value of the variable `a` where noted in the code.
# --hints--
Your code should use `console.log()` to check the value of the variable `a`.
```js
assert(code.match(/console\.log\(a\)/g));
```
</section>
# --seed--
## Challenge Seed
<section id='challengeSeed'>
<div id='js-seed'>
## --seed-contents--
```js
let a = 5;
@ -47,18 +44,8 @@ let sumAB = a + b;
console.log(sumAB);
```
</div>
</section>
## Solution
<section id='solution'>
# --solutions--
```js
var a = 5; console.log(a);
```
</section>

View File

@ -5,10 +5,11 @@ challengeType: 1
forumTopicId: 18374
---
## Description
<section id='description'>
You can use <code>typeof</code> to check the data structure, or type, of a variable. This is useful in debugging when working with multiple data types. If you think you're adding two numbers, but one is actually a string, the results can be unexpected. Type errors can lurk in calculations or function calls. Be careful especially when you're accessing and working with external data in the form of a JavaScript Object Notation (JSON) object.
Here are some examples using <code>typeof</code>:
# --description--
You can use `typeof` to check the data structure, or type, of a variable. This is useful in debugging when working with multiple data types. If you think you're adding two numbers, but one is actually a string, the results can be unexpected. Type errors can lurk in calculations or function calls. Be careful especially when you're accessing and working with external data in the form of a JavaScript Object Notation (JSON) object.
Here are some examples using `typeof`:
```js
console.log(typeof ""); // outputs "string"
@ -17,56 +18,46 @@ console.log(typeof []); // outputs "object"
console.log(typeof {}); // outputs "object"
```
JavaScript recognizes six primitive (immutable) data types: <code>Boolean</code>, <code>Null</code>, <code>Undefined</code>, <code>Number</code>, <code>String</code>, and <code>Symbol</code> (new with ES6) and one type for mutable items: <code>Object</code>. Note that in JavaScript, arrays are technically a type of object.
</section>
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
<section id='instructions'>
Add two <code>console.log()</code> statements to check the <code>typeof</code> each of the two variables <code>seven</code> and <code>three</code> in the code.
</section>
# --instructions--
## Tests
<section id='tests'>
Add two `console.log()` statements to check the `typeof` each of the two variables `seven` and `three` in the code.
```yml
tests:
- text: Your code should use <code>typeof</code> in two <code>console.log()</code> statements to check the type of the variables.
testString: assert(code.match(/console\.log\(typeof[\( ].*\)?\)/g).length == 2);
- text: Your code should use <code>typeof</code> to check the type of the variable <code>seven</code>.
testString: assert(code.match(/typeof[\( ]seven\)?/g));
- text: Your code should use <code>typeof</code> to check the type of the variable <code>three</code>.
testString: assert(code.match(/typeof[\( ]three\)?/g));
# --hints--
Your code should use `typeof` in two `console.log()` statements to check the type of the variables.
```js
assert(code.match(/console\.log\(typeof[\( ].*\)?\)/g).length == 2);
```
</section>
Your code should use `typeof` to check the type of the variable `seven`.
## Challenge Seed
<section id='challengeSeed'>
```js
assert(code.match(/typeof[\( ]seven\)?/g));
```
<div id='js-seed'>
Your code should use `typeof` to check the type of the variable `three`.
```js
assert(code.match(/typeof[\( ]three\)?/g));
```
# --seed--
## --seed-contents--
```js
let seven = 7;
let three = "3";
console.log(seven + three);
// Only change code below this line
```
</div>
</section>
## Solution
<section id='solution'>
# --solutions--
```js
let seven = 7;let three = "3";console.log(typeof seven);
console.log(typeof three);
```
</section>