fix: replace inline code blocks (#41576)

pull/41586/head
Randell Dawson 2021-03-25 15:07:48 -06:00 committed by GitHub
parent 8cc172d9e8
commit b5ed2619eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
25 changed files with 103 additions and 37 deletions

View File

@ -13,11 +13,15 @@ You can add new properties to existing JavaScript objects the same way you would
Here's how we would add a `bark` property to `ourDog`:
`ourDog.bark = "bow-wow";`
```js
ourDog.bark = "bow-wow";
```
or
`ourDog["bark"] = "bow-wow";`
```js
ourDog["bark"] = "bow-wow";
```
Now when we evaluate `ourDog.bark`, we'll get his bark, `bow-wow`.

View File

@ -13,7 +13,9 @@ If you'll recall from our discussion of [Storing Values with the Assignment Oper
Assume we have pre-defined a function `sum` which adds two numbers together, then:
`ourSum = sum(5, 12);`
```js
ourSum = sum(5, 12);
```
will call `sum` function, which returns a value of `17` and assigns it to `ourSum` variable.

View File

@ -11,7 +11,9 @@ dashedName: compound-assignment-with-augmented-addition
In programming, it is common to use assignments to modify the contents of a variable. Remember that everything to the right of the equals sign is evaluated first, so we can say:
`myVar = myVar + 5;`
```js
myVar = myVar + 5;
```
to add `5` to `myVar`. Since this is such a common pattern, there are operators which do both a mathematical operation and assignment in one step.

View File

@ -11,11 +11,15 @@ dashedName: compound-assignment-with-augmented-division
The `/=` operator divides a variable by another number.
`myVar = myVar / 5;`
```js
myVar = myVar / 5;
```
Will divide `myVar` by `5`. This can be rewritten as:
`myVar /= 5;`
```js
myVar /= 5;
```
# --instructions--

View File

@ -11,11 +11,15 @@ dashedName: compound-assignment-with-augmented-multiplication
The `*=` operator multiplies a variable by a number.
`myVar = myVar * 5;`
```js
myVar = myVar * 5;
```
will multiply `myVar` by `5`. This can be rewritten as:
`myVar *= 5;`
```js
myVar *= 5;
```
# --instructions--

View File

@ -11,11 +11,15 @@ dashedName: compound-assignment-with-augmented-subtraction
Like the `+=` operator, `-=` subtracts a number from a variable.
`myVar = myVar - 5;`
```js
myVar = myVar - 5;
```
will subtract `5` from `myVar`. This can be rewritten as:
`myVar -= 5;`
```js
myVar -= 5;
```
# --instructions--

View File

@ -17,9 +17,7 @@ Having more high cards remaining in the deck favors the player. Each card is ass
You will write a card counting function. It will receive a `card` parameter, which can be a number or a string, and increment or decrement the global `count` variable according to the card's value (see table). The function will then return a string with the current count and the string `Bet` if the count is positive, or `Hold` if the count is zero or negative. The current count and the player's decision (`Bet` or `Hold`) should be separated by a single space.
**Example Output**
`-3 Hold`
`5 Bet`
**Example Outputs:** `-3 Hold` or `5 Bet`
**Hint**
Do NOT reset `count` to 0 when value is 7, 8, or 9.

View File

@ -11,7 +11,9 @@ dashedName: declare-string-variables
Previously we have used the code
`var myName = "your name";`
```js
var myName = "your name";
```
`"your name"` is called a <dfn>string</dfn> <dfn>literal</dfn>. It is a string because it is a series of zero or more characters enclosed in single or double quotes.

View File

@ -11,11 +11,15 @@ dashedName: decrement-a-number-with-javascript
You can easily <dfn>decrement</dfn> or decrease a variable by one with the `--` operator.
`i--;`
```js
i--;
```
is the equivalent of
`i = i - 1;`
```js
i = i - 1;
```
**Note:** The entire line becomes `i--;`, eliminating the need for the equal sign.

View File

@ -11,7 +11,9 @@ dashedName: delete-properties-from-a-javascript-object
We can also delete properties from objects like this:
`delete ourDog.bark;`
```js
delete ourDog.bark;
```
Example:

View File

@ -13,17 +13,23 @@ When you are defining a string you must start and end with a single or double qu
In JavaScript, you can <dfn>escape</dfn> a quote from considering it as an end of string quote by placing a <dfn>backslash</dfn> (`\`) in front of the quote.
`var sampleStr = "Alan said, \"Peter is learning JavaScript\".";`
```js
var sampleStr = "Alan said, \"Peter is learning JavaScript\".";
```
This signals to JavaScript that the following quote is not the end of the string, but should instead appear inside the string. So if you were to print this to the console, you would get:
`Alan said, "Peter is learning JavaScript".`
```js
Alan said, "Peter is learning JavaScript".
```
# --instructions--
Use <dfn>backslashes</dfn> to assign a string to the `myStr` variable so that if you were to print it to the console, you would see:
`I am a "double quoted" string inside "double quotes".`
```js
I am a "double quoted" string inside "double quotes".
```
# --hints--

View File

@ -17,7 +17,9 @@ Remember that `Math.random()` can never quite return a `1` and, because we're ro
Putting everything together, this is what our code looks like:
`Math.floor(Math.random() * 20);`
```js
Math.floor(Math.random() * 20);
```
We are calling `Math.random()`, multiplying the result by 20, then passing the value to `Math.floor()` function to round the value down to the nearest whole number.

View File

@ -15,7 +15,9 @@ To do this, we'll define a minimum number `min` and a maximum number `max`.
Here's the formula we'll use. Take a moment to read it and try to understand what this code is doing:
`Math.floor(Math.random() * (max - min + 1)) + min`
```js
Math.floor(Math.random() * (max - min + 1)) + min
```
# --instructions--

View File

@ -11,11 +11,15 @@ dashedName: increment-a-number-with-javascript
You can easily <dfn>increment</dfn> or add one to a variable with the `++` operator.
`i++;`
```js
i++;
```
is the equivalent of
`i = i + 1;`
```js
i = i + 1;
```
**Note:** The entire line becomes `i++;`, eliminating the need for the equal sign.

View File

@ -11,7 +11,9 @@ dashedName: initializing-variables-with-the-assignment-operator
It is common to <dfn>initialize</dfn> a variable to an initial value in the same line as it is declared.
`var myVar = 0;`
```js
var myVar = 0;
```
Creates a new variable called `myVar` and assigns it an initial value of `0`.

View File

@ -13,7 +13,9 @@ Create a shopping list in the variable `myList`. The list should be a multi-dime
The first element in each sub-array should contain a string with the name of the item. The second element should be a number representing the quantity i.e.
`["Chocolate Bar", 15]`
```js
["Chocolate Bar", 15]
```
There should be at least 5 sub-arrays in the list.

View File

@ -13,7 +13,9 @@ With JavaScript `array` variables, we can store several pieces of data in one pl
You start an array declaration with an opening square bracket, end it with a closing square bracket, and put a comma between each entry, like this:
`var sandwich = ["peanut butter", "jelly", "bread"]`
```js
var sandwich = ["peanut butter", "jelly", "bread"]
```
# --instructions--

View File

@ -11,7 +11,9 @@ dashedName: storing-values-with-the-assignment-operator
In JavaScript, you can store a value in a variable with the <dfn>assignment</dfn> operator (`=`).
`myVariable = 5;`
```js
myVariable = 5;
```
This assigns the `Number` value `5` to `myVariable`.

View File

@ -13,11 +13,15 @@ The `parseInt()` function parses a string and returns an integer. It takes a sec
The function call looks like:
`parseInt(string, radix);`
```js
parseInt(string, radix);
```
And here's an example:
`var a = parseInt("11", 2);`
```js
var a = parseInt("11", 2);
```
The radix variable says that `11` is in the binary system, or base 2. This example converts the string `11` to an integer `3`.

View File

@ -11,7 +11,9 @@ dashedName: use-the-parseint-function
The `parseInt()` function parses a string and returns an integer. Here's an example:
`var a = parseInt("007");`
```js
var a = parseInt("007");
```
The above function converts the string `007` to the integer `7`. If the first character in the string can't be converted into a number, then it returns `NaN`.

View File

@ -16,7 +16,9 @@ The `console.log()` method, which "prints" the output of what's within its paren
Here's an example to print the string `Hello world!` to the console:
`console.log('Hello world!');`
```js
console.log('Hello world!');
```
# --instructions--

View File

@ -10,7 +10,9 @@ dashedName: learn-about-functional-programming
Functional programming is a style of programming where solutions are simple, isolated functions, without any side effects outside of the function scope.
`INPUT -> PROCESS -> OUTPUT`
```js
INPUT -> PROCESS -> OUTPUT
```
Functional programming is about:

View File

@ -14,7 +14,9 @@ For example, `addTogether(2, 3)` should return `5`, and `addTogether(2)` should
Calling this returned function with a single argument will then return the sum:
`var sumTwoAnd = addTogether(2);`
```js
var sumTwoAnd = addTogether(2);
```
`sumTwoAnd(3)` returns `5`.

View File

@ -9,11 +9,15 @@ dashedName: part-18
The `reduce()` method takes a callback function with at least two arguments, an accumulator and a current value:
`function(accumulator, currentValue) { /* code to run */ }`
```js
function(accumulator, currentValue) { /* code to run */ }
```
or using arrow functions:
`(accumulator, currentValue) => { /* code to run */ }`
```js
(accumulator, currentValue) => { /* code to run */ }
```
Insert the above callback function as an argument in the `.reduce()` method.

View File

@ -10,7 +10,9 @@ dashedName: make-code-more-reusable-with-the-this-keyword
The last challenge introduced a method to the `duck` object. It used `duck.name` dot notation to access the value for the `name` property within the return statement:
`sayName: function() {return "The name of this duck is " + duck.name + ".";}`
```js
sayName: function() {return "The name of this duck is " + duck.name + ".";}
```
While this is a valid way to access the object's property, there is a pitfall here. If the variable name changes, any code referencing the original name would need to be updated as well. In a short object definition, it isn't a problem, but if an object has many references to its properties there is a greater chance for error.