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:
Nicholas Carrigan (he/him)
2021-03-02 16:12:12 -08:00
committed by GitHub
parent 57f3c80345
commit 7117919d36
226 changed files with 1236 additions and 1077 deletions

View File

@ -19,12 +19,13 @@ Array indexes are written in the same bracket notation that strings use, except
```js
var array = [50,60,70];
array[0]; // equals 50
var data = array[1]; // equals 60
array[0];
var data = array[1];
```
**Note**
There shouldn't be any spaces between the array name and the square brackets, like `array [0]`. Although JavaScript is able to process this correctly, this may confuse other programmers reading your code.
`array[0]` is now `50`, and `data` has the value `60`.
**Note:** There shouldn't be any spaces between the array name and the square brackets, like `array [0]`. Although JavaScript is able to process this correctly, this may confuse other programmers reading your code.
# --instructions--

View File

@ -20,13 +20,14 @@ var arr = [
[7,8,9],
[[10,11,12], 13, 14]
];
arr[3]; // equals [[10,11,12], 13, 14]
arr[3][0]; // equals [10,11,12]
arr[3][0][1]; // equals 11
arr[3];
arr[3][0];
arr[3][0][1];
```
**Note**
There shouldn't be any spaces between the array name and the square brackets, like `array [0][0]` and even this `array [0] [0]` is not allowed. Although JavaScript is able to process this correctly, this may confuse other programmers reading your code.
`arr[3]` is `[[10, 11, 12], 13, 14]`, `arr[3][0]` is `[10, 11, 12]`, and `arr[3][0][1]` is `11`.
**Note:** There shouldn't be any spaces between the array name and the square brackets, like `array [0][0]` and even this `array [0] [0]` is not allowed. Although JavaScript is able to process this correctly, this may confuse other programmers reading your code.
# --instructions--

View File

@ -9,7 +9,7 @@ dashedName: accessing-nested-arrays
# --description--
As we have seen in earlier examples, objects can contain both nested objects and nested arrays. Similar to accessing nested objects, Array bracket notation can be chained to access nested arrays.
As we have seen in earlier examples, objects can contain both nested objects and nested arrays. Similar to accessing nested objects, array bracket notation can be chained to access nested arrays.
Here is an example of how to access a nested array:
@ -32,17 +32,19 @@ var ourPets = [
]
}
];
ourPets[0].names[1]; // "Fluffy"
ourPets[1].names[0]; // "Spot"
ourPets[0].names[1];
ourPets[1].names[0];
```
`ourPets[0].names[1]` would be the string `Fluffy`, and `ourPets[1].names[0]` would be the string `Spot`.
# --instructions--
Retrieve the second tree from the variable `myPlants` using object dot and array bracket notation.
# --hints--
`secondTree` should equal "pine".
`secondTree` should equal the string `pine`.
```js
assert(secondTree === 'pine');

View File

@ -26,17 +26,19 @@ var ourStorage = {
"bottom drawer": "soda"
}
};
ourStorage.cabinet["top drawer"].folder2; // "secrets"
ourStorage.desk.drawer; // "stapler"
ourStorage.cabinet["top drawer"].folder2;
ourStorage.desk.drawer;
```
`ourStorage.cabinet["top drawer"].folder2` would be the string `secrets`, and `ourStorage.desk.drawer` would be the string `stapler`.
# --instructions--
Access the `myStorage` object and assign the contents of the `glove box` property to the `gloveBoxContents` variable. Use dot notation for all properties where possible, otherwise use bracket notation.
# --hints--
`gloveBoxContents` should equal "maps".
`gloveBoxContents` should equal the string `maps`.
```js
assert(gloveBoxContents === 'maps');

View File

@ -21,16 +21,18 @@ var myObj = {
"More Space": "Spock",
"NoSpace": "USS Enterprise"
};
myObj["Space Name"]; // Kirk
myObj['More Space']; // Spock
myObj["NoSpace"]; // USS Enterprise
myObj["Space Name"];
myObj['More Space'];
myObj["NoSpace"];
```
`myObj["Space Name"]` would be the string `Kirk`, `myObj['More Space']` would be the string `Spock`, and `myObj["NoSpace"]` would be the string `USS Enterprise`.
Note that property names with spaces in them must be in quotes (single or double).
# --instructions--
Read the values of the properties `"an entree"` and `"the drink"` of `testObj` using bracket notation and assign them to `entreeValue` and `drinkValue` respectively.
Read the values of the properties `an entree` and `the drink` of `testObj` using bracket notation and assign them to `entreeValue` and `drinkValue` respectively.
# --hints--
@ -40,7 +42,7 @@ Read the values of the properties `"an entree"` and `"the drink"` of `testObj` u
assert(typeof entreeValue === 'string');
```
The value of `entreeValue` should be `"hamburger"`
The value of `entreeValue` should be the string `hamburger`
```js
assert(entreeValue === 'hamburger');
@ -52,7 +54,7 @@ assert(entreeValue === 'hamburger');
assert(typeof drinkValue === 'string');
```
The value of `drinkValue` should be `"water"`
The value of `drinkValue` should be the string `water`
```js
assert(drinkValue === 'water');

View File

@ -20,10 +20,11 @@ var myObj = {
prop1: "val1",
prop2: "val2"
};
var prop1val = myObj.prop1; // val1
var prop2val = myObj.prop2; // val2
var prop1val = myObj.prop1;
var prop2val = myObj.prop2;
```
`prop1val` would have a value of the string `val1`, and `prop2val` would have a value of the string `val2`.
# --instructions--
Read in the property values of `testObj` using dot notation. Set the variable `hatValue` equal to the object's property `hat` and set the variable `shirtValue` equal to the object's property `shirt`.
@ -36,7 +37,7 @@ Read in the property values of `testObj` using dot notation. Set the variable `h
assert(typeof hatValue === 'string');
```
The value of `hatValue` should be `"ballcap"`
The value of `hatValue` should be the string `ballcap`
```js
assert(hatValue === 'ballcap');
@ -48,7 +49,7 @@ assert(hatValue === 'ballcap');
assert(typeof shirtValue === 'string');
```
The value of `shirtValue` should be `"jersey"`
The value of `shirtValue` should be the string `jersey`
```js
assert(shirtValue === 'jersey');

View File

@ -19,9 +19,11 @@ var dogs = {
};
var myDog = "Hunter";
var myBreed = dogs[myDog];
console.log(myBreed); // "Doberman"
console.log(myBreed);
```
The string `Doberman` would be displayed in the console.
Another way you can use this concept is when the property's name is collected dynamically during the program execution, as follows:
```js
@ -32,10 +34,12 @@ function propPrefix(str) {
var s = "prop";
return s + str;
}
var someProp = propPrefix("Name"); // someProp now holds the value 'propName'
console.log(someObj[someProp]); // "John"
var someProp = propPrefix("Name");
console.log(someObj[someProp]);
```
`someProp` would have a value of the string `propName`, and the string `John` would be displayed in the console.
Note that we do *not* use quotes around the variable name when using it to access the property because we are using the *value* of the variable, not the *name*.
# --instructions--
@ -56,7 +60,7 @@ The variable `player` should be a string
assert(typeof player === 'string');
```
The value of `player` should be "Montana"
The value of `player` should be the string `Montana`
```js
assert(player === 'Montana');

View File

@ -11,7 +11,7 @@ dashedName: add-new-properties-to-a-javascript-object
You can add new properties to existing JavaScript objects the same way you would modify them.
Here's how we would add a `"bark"` property to `ourDog`:
Here's how we would add a `bark` property to `ourDog`:
`ourDog.bark = "bow-wow";`
@ -19,7 +19,7 @@ or
`ourDog["bark"] = "bow-wow";`
Now when we evaluate `ourDog.bark`, we'll get his bark, "bow-wow".
Now when we evaluate `ourDog.bark`, we'll get his bark, `bow-wow`.
Example:
@ -36,17 +36,17 @@ ourDog.bark = "bow-wow";
# --instructions--
Add a `"bark"` property to `myDog` and set it to a dog sound, such as "woof". You may use either dot or bracket notation.
Add a `bark` property to `myDog` and set it to a dog sound, such as "woof". You may use either dot or bracket notation.
# --hints--
You should add the property `"bark"` to `myDog`.
You should add the property `bark` to `myDog`.
```js
assert(myDog.bark !== undefined);
```
You should not add `"bark"` to the setup section.
You should not add `bark` to the setup section.
```js
assert(!/bark[^\n]:/.test(code));

View File

@ -18,9 +18,11 @@ JavaScript uses the `+` symbol as an addition operator when placed between two n
**Example:**
```js
myVar = 5 + 10; // assigned 15
myVar = 5 + 10;
```
`myVar` now has the value `15`.
# --instructions--
Change the `0` so that sum will equal `20`.

View File

@ -31,38 +31,38 @@ switch (num) {
# --instructions--
Write a switch statement to set `answer` for the following conditions:
`"a"` - "apple"
`"b"` - "bird"
`"c"` - "cat"
`default` - "stuff"
`a` - `apple`
`b` - `bird`
`c` - `cat`
`default` - `stuff`
# --hints--
`switchOfStuff("a")` should have a value of "apple"
`switchOfStuff("a")` should return the string `apple`
```js
assert(switchOfStuff('a') === 'apple');
```
`switchOfStuff("b")` should have a value of "bird"
`switchOfStuff("b")` should return the string `bird`
```js
assert(switchOfStuff('b') === 'bird');
```
`switchOfStuff("c")` should have a value of "cat"
`switchOfStuff("c")` should return the string `cat`
```js
assert(switchOfStuff('c') === 'cat');
```
`switchOfStuff("d")` should have a value of "stuff"
`switchOfStuff("d")` should return the string `stuff`
```js
assert(switchOfStuff('d') === 'stuff');
```
`switchOfStuff(4)` should have a value of "stuff"
`switchOfStuff(4)` should return the string `stuff`
```js
assert(switchOfStuff(4) === 'stuff');

View File

@ -17,9 +17,10 @@ Example:
var anAdjective = "awesome!";
var ourStr = "freeCodeCamp is ";
ourStr += anAdjective;
// ourStr is now "freeCodeCamp is awesome!"
```
`ourStr` would have the value `freeCodeCamp is awesome!`.
# --instructions--
Set `someAdjective` to a string of at least 3 characters and append it to `myStr` using the `+=` operator.

View File

@ -32,7 +32,7 @@ You should not change code above the specified comment.
assert(/var a;/.test(code) && /a = 7;/.test(code) && /var b;/.test(code));
```
`b` should have a value of 7.
`b` should have a value of `7`.
```js
assert(typeof b === 'number' && b === 7);

View File

@ -26,7 +26,7 @@ var cat = {
};
```
In this example, all the properties are stored as strings, such as - `"name"`, `"legs"`, and `"tails"`. However, you can also use numbers as properties. You can even omit the quotes for single-word string properties, as follows:
In this example, all the properties are stored as strings, such as - `name`, `legs`, and `tails`. However, you can also use numbers as properties. You can even omit the quotes for single-word string properties, as follows:
```js
var anotherObject = {
@ -40,9 +40,9 @@ However, if your object has any non-string properties, JavaScript will automatic
# --instructions--
Make an object that represents a dog called `myDog` which contains the properties `"name"` (a string), `"legs"`, `"tails"` and `"friends"`.
Make an object that represents a dog called `myDog` which contains the properties `name` (a string), `legs`, `tails` and `friends`.
You can set these object properties to whatever values you want, as long as `"name"` is a string, `"legs"` and `"tails"` are numbers, and `"friends"` is an array.
You can set these object properties to whatever values you want, as long as `name` is a string, `legs` and `tails` are numbers, and `friends` is an array.
# --hints--

View File

@ -28,11 +28,11 @@ if (condition1) {
Write chained `if`/`else if` statements to fulfill the following conditions:
`num < 5` - return "Tiny"
`num < 10` - return "Small"
`num < 15` - return "Medium"
`num < 20` - return "Large"
`num >= 20` - return "Huge"
`num < 5` - return `Tiny`
`num < 10` - return `Small`
`num < 15` - return `Medium`
`num < 20` - return `Large`
`num >= 20` - return `Huge`
# --hints--
@ -54,61 +54,61 @@ You should have at least one `return` statement
assert(code.match(/return/g).length >= 1);
```
`testSize(0)` should return "Tiny"
`testSize(0)` should return the string `Tiny`
```js
assert(testSize(0) === 'Tiny');
```
`testSize(4)` should return "Tiny"
`testSize(4)` should return the string `Tiny`
```js
assert(testSize(4) === 'Tiny');
```
`testSize(5)` should return "Small"
`testSize(5)` should return the string `Small`
```js
assert(testSize(5) === 'Small');
```
`testSize(8)` should return "Small"
`testSize(8)` should return the string `Small`
```js
assert(testSize(8) === 'Small');
```
`testSize(10)` should return "Medium"
`testSize(10)` should return the string `Medium`
```js
assert(testSize(10) === 'Medium');
```
`testSize(14)` should return "Medium"
`testSize(14)` should return the string `Medium`
```js
assert(testSize(14) === 'Medium');
```
`testSize(15)` should return "Large"
`testSize(15)` should return the string `Large`
```js
assert(testSize(15) === 'Large');
```
`testSize(17)` should return "Large"
`testSize(17)` should return the string `Large`
```js
assert(testSize(17) === 'Large');
```
`testSize(20)` should return "Huge"
`testSize(20)` should return the string `Huge`
```js
assert(testSize(20) === 'Huge');
```
`testSize(25)` should return "Huge"
`testSize(25)` should return the string `Huge`
```js
assert(testSize(25) === 'Huge');

View File

@ -13,21 +13,20 @@ Comments are lines of code that JavaScript will intentionally ignore. Comments a
There are two ways to write comments in JavaScript:
Using `//` will tell JavaScript to ignore the remainder of the text on the current line:
Using `//` will tell JavaScript to ignore the remainder of the text on the current line. This is an in-line comment:
```js
// This is an in-line comment.
```
You can make a multi-line comment beginning with `/*` and ending with `*/`:
You can make a multi-line comment beginning with `/*` and ending with `*/`. This is a multi-line comment:
```js
/* This is a
multi-line comment */
```
**Best Practice**
As you write code, you should regularly add comments to clarify the function of parts of your code. Good commenting can help communicate the intent of your code—both for others *and* for your future self.
**NOTE:** As you write code, you should regularly add comments to clarify the function of parts of your code. Good commenting can help communicate the intent of your code—both for others *and* for your future self.
# --instructions--

View File

@ -22,34 +22,36 @@ function equalityTest(myVal) {
}
```
If `myVal` is equal to `10`, the equality operator returns `true`, so the code in the curly braces will execute, and the function will return `"Equal"`. Otherwise, the function will return `"Not Equal"`. In order for JavaScript to compare two different <dfn>data types</dfn> (for example, `numbers` and `strings`), it must convert one type to another. This is known as "Type Coercion". Once it does, however, it can compare terms as follows:
If `myVal` is equal to `10`, the equality operator returns `true`, so the code in the curly braces will execute, and the function will return `Equal`. Otherwise, the function will return `Not Equal`. In order for JavaScript to compare two different <dfn>data types</dfn> (for example, `numbers` and `strings`), it must convert one type to another. This is known as Type Coercion. Once it does, however, it can compare terms as follows:
```js
1 == 1 // true
1 == 2 // false
1 == '1' // true
"3" == 3 // true
1 == 1
1 == 2
1 == '1'
"3" == 3
```
In order, these expressions would evaluate to `true`, `false`, `true`, and `true`.
# --instructions--
Add the equality operator to the indicated line so that the function will return "Equal" when `val` is equivalent to `12`.
Add the equality operator to the indicated line so that the function will return the string `Equal` when `val` is equivalent to `12`.
# --hints--
`testEqual(10)` should return "Not Equal"
`testEqual(10)` should return the string `Not Equal`
```js
assert(testEqual(10) === 'Not Equal');
```
`testEqual(12)` should return "Equal"
`testEqual(12)` should return the string `Equal`
```js
assert(testEqual(12) === 'Equal');
```
`testEqual("12")` should return "Equal"
`testEqual("12")` should return the string `Equal`
```js
assert(testEqual('12') === 'Equal');

View File

@ -16,55 +16,57 @@ Like the equality operator, greater than operator will convert data types of val
**Examples**
```js
5 > 3 // true
7 > '3' // true
2 > 3 // false
'1' > 9 // false
5 > 3
7 > '3'
2 > 3
'1' > 9
```
In order, these expressions would evaluate to `true`, `true`, `false`, and `false`.
# --instructions--
Add the greater than operator to the indicated lines so that the return statements make sense.
# --hints--
`testGreaterThan(0)` should return "10 or Under"
`testGreaterThan(0)` should return the string `10 or Under`
```js
assert(testGreaterThan(0) === '10 or Under');
```
`testGreaterThan(10)` should return "10 or Under"
`testGreaterThan(10)` should return the string `10 or Under`
```js
assert(testGreaterThan(10) === '10 or Under');
```
`testGreaterThan(11)` should return "Over 10"
`testGreaterThan(11)` should return the string `Over 10`
```js
assert(testGreaterThan(11) === 'Over 10');
```
`testGreaterThan(99)` should return "Over 10"
`testGreaterThan(99)` should return the string `Over 10`
```js
assert(testGreaterThan(99) === 'Over 10');
```
`testGreaterThan(100)` should return "Over 10"
`testGreaterThan(100)` should return the string `Over 10`
```js
assert(testGreaterThan(100) === 'Over 10');
```
`testGreaterThan(101)` should return "Over 100"
`testGreaterThan(101)` should return the string `Over 100`
```js
assert(testGreaterThan(101) === 'Over 100');
```
`testGreaterThan(150)` should return "Over 100"
`testGreaterThan(150)` should return the string `Over 100`
```js
assert(testGreaterThan(150) === 'Over 100');

View File

@ -16,55 +16,57 @@ Like the equality operator, the `>=` will convert data types while comparing.
**Examples**
```js
6 >= 6 // true
7 >= '3' // true
2 >= 3 // false
'7' >= 9 // false
6 >= 6
7 >= '3'
2 >= 3
'7' >= 9
```
In order, these expressions would evaluate to `true`, `true`, `false`, and `false`.
# --instructions--
Add the greater than or equal to operator to the indicated lines so that the return statements make sense.
# --hints--
`testGreaterOrEqual(0)` should return "Less than 10"
`testGreaterOrEqual(0)` should return the string `Less than 10`
```js
assert(testGreaterOrEqual(0) === 'Less than 10');
```
`testGreaterOrEqual(9)` should return "Less than 10"
`testGreaterOrEqual(9)` should return the string `Less than 10`
```js
assert(testGreaterOrEqual(9) === 'Less than 10');
```
`testGreaterOrEqual(10)` should return "10 or Over"
`testGreaterOrEqual(10)` should return the string `10 or Over`
```js
assert(testGreaterOrEqual(10) === '10 or Over');
```
`testGreaterOrEqual(11)` should return "10 or Over"
`testGreaterOrEqual(11)` should return the string `10 or Over`
```js
assert(testGreaterOrEqual(11) === '10 or Over');
```
`testGreaterOrEqual(19)` should return "10 or Over"
`testGreaterOrEqual(19)` should return the string `10 or Over`
```js
assert(testGreaterOrEqual(19) === '10 or Over');
```
`testGreaterOrEqual(100)` should return "20 or Over"
`testGreaterOrEqual(100)` should return the string `20 or Over`
```js
assert(testGreaterOrEqual(100) === '20 or Over');
```
`testGreaterOrEqual(21)` should return "20 or Over"
`testGreaterOrEqual(21)` should return the string `20 or Over`
```js
assert(testGreaterOrEqual(21) === '20 or Over');

View File

@ -9,49 +9,51 @@ dashedName: comparison-with-the-inequality-operator
# --description--
The inequality operator (`!=`) is the opposite of the equality operator. It means "Not Equal" and returns `false` where equality would return `true` and *vice versa*. Like the equality operator, the inequality operator will convert data types of values while comparing.
The inequality operator (`!=`) is the opposite of the equality operator. It means not equal and returns `false` where equality would return `true` and *vice versa*. Like the equality operator, the inequality operator will convert data types of values while comparing.
**Examples**
```js
1 != 2 // true
1 != "1" // false
1 != '1' // false
1 != true // false
0 != false // false
1 != 2
1 != "1"
1 != '1'
1 != true
0 != false
```
In order, these expressions would evaluate to `true`, `false`, `false`, `false`, and `false`.
# --instructions--
Add the inequality operator `!=` in the `if` statement so that the function will return "Not Equal" when `val` is not equivalent to `99`
Add the inequality operator `!=` in the `if` statement so that the function will return the string `Not Equal` when `val` is not equivalent to `99`
# --hints--
`testNotEqual(99)` should return "Equal"
`testNotEqual(99)` should return the string `Equal`
```js
assert(testNotEqual(99) === 'Equal');
```
`testNotEqual("99")` should return "Equal"
`testNotEqual("99")` should return the string `Equal`
```js
assert(testNotEqual('99') === 'Equal');
```
`testNotEqual(12)` should return "Not Equal"
`testNotEqual(12)` should return the string `Not Equal`
```js
assert(testNotEqual(12) === 'Not Equal');
```
`testNotEqual("12")` should return "Not Equal"
`testNotEqual("12")` should return the string `Not Equal`
```js
assert(testNotEqual('12') === 'Not Equal');
```
`testNotEqual("bob")` should return "Not Equal"
`testNotEqual("bob")` should return the string `Not Equal`
```js
assert(testNotEqual('bob') === 'Not Equal');

View File

@ -14,50 +14,52 @@ The <dfn>less than</dfn> operator (`<`) compares the values of two numbers. If t
**Examples**
```js
2 < 5 // true
'3' < 7 // true
5 < 5 // false
3 < 2 // false
'8' < 4 // false
2 < 5
'3' < 7
5 < 5
3 < 2
'8' < 4
```
In order, these expressions would evaluate to `true`, `true`, `false`, `false`, and `false`.
# --instructions--
Add the less than operator to the indicated lines so that the return statements make sense.
# --hints--
`testLessThan(0)` should return "Under 25"
`testLessThan(0)` should return the string `Under 25`
```js
assert(testLessThan(0) === 'Under 25');
```
`testLessThan(24)` should return "Under 25"
`testLessThan(24)` should return the string `Under 25`
```js
assert(testLessThan(24) === 'Under 25');
```
`testLessThan(25)` should return "Under 55"
`testLessThan(25)` should return the string `Under 55`
```js
assert(testLessThan(25) === 'Under 55');
```
`testLessThan(54)` should return "Under 55"
`testLessThan(54)` should return the string `Under 55`
```js
assert(testLessThan(54) === 'Under 55');
```
`testLessThan(55)` should return "55 or Over"
`testLessThan(55)` should return the string `55 or Over`
```js
assert(testLessThan(55) === '55 or Over');
```
`testLessThan(99)` should return "55 or Over"
`testLessThan(99)` should return the string `55 or Over`
```js
assert(testLessThan(99) === '55 or Over');

View File

@ -14,56 +14,58 @@ The less than or equal to operator (`<=`) compares the values of two numbers. If
**Examples**
```js
4 <= 5 // true
'7' <= 7 // true
5 <= 5 // true
3 <= 2 // false
'8' <= 4 // false
4 <= 5
'7' <= 7
5 <= 5
3 <= 2
'8' <= 4
```
In order, these expressions would evaluate to `true`, `true`, `true`, `false`, and `false`.
# --instructions--
Add the less than or equal to operator to the indicated lines so that the return statements make sense.
# --hints--
`testLessOrEqual(0)` should return "Smaller Than or Equal to 12"
`testLessOrEqual(0)` should return the string `Smaller Than or Equal to 12`
```js
assert(testLessOrEqual(0) === 'Smaller Than or Equal to 12');
```
`testLessOrEqual(11)` should return "Smaller Than or Equal to 12"
`testLessOrEqual(11)` should return the string `Smaller Than or Equal to 12`
```js
assert(testLessOrEqual(11) === 'Smaller Than or Equal to 12');
```
`testLessOrEqual(12)` should return "Smaller Than or Equal to 12"
`testLessOrEqual(12)` should return the string `Smaller Than or Equal to 12`
```js
assert(testLessOrEqual(12) === 'Smaller Than or Equal to 12');
```
`testLessOrEqual(23)` should return "Smaller Than or Equal to 24"
`testLessOrEqual(23)` should return the string `Smaller Than or Equal to 24`
```js
assert(testLessOrEqual(23) === 'Smaller Than or Equal to 24');
```
`testLessOrEqual(24)` should return "Smaller Than or Equal to 24"
`testLessOrEqual(24)` should return the string `Smaller Than or Equal to 24`
```js
assert(testLessOrEqual(24) === 'Smaller Than or Equal to 24');
```
`testLessOrEqual(25)` should return "More Than 24"
`testLessOrEqual(25)` should return the string `More Than 24`
```js
assert(testLessOrEqual(25) === 'More Than 24');
```
`testLessOrEqual(55)` should return "More Than 24"
`testLessOrEqual(55)` should return the string `More Than 24`
```js
assert(testLessOrEqual(55) === 'More Than 24');

View File

@ -16,31 +16,33 @@ If the values being compared have different types, they are considered unequal,
**Examples**
```js
3 === 3 // true
3 === '3' // false
3 === 3
3 === '3'
```
These conditions would return `true` and `false` respectively.
In the second example, `3` is a `Number` type and `'3'` is a `String` type.
# --instructions--
Use the strict equality operator in the `if` statement so the function will return "Equal" when `val` is strictly equal to `7`
Use the strict equality operator in the `if` statement so the function will return the string `Equal` when `val` is strictly equal to `7`
# --hints--
`testStrict(10)` should return "Not Equal"
`testStrict(10)` should return the string `Not Equal`
```js
assert(testStrict(10) === 'Not Equal');
```
`testStrict(7)` should return "Equal"
`testStrict(7)` should return the string `Equal`
```js
assert(testStrict(7) === 'Equal');
```
`testStrict("7")` should return "Not Equal"
`testStrict("7")` should return the string `Not Equal`
```js
assert(testStrict('7') === 'Not Equal');

View File

@ -14,36 +14,38 @@ The strict inequality operator (`!==`) is the logical opposite of the strict equ
**Examples**
```js
3 !== 3 // false
3 !== '3' // true
4 !== 3 // true
3 !== 3
3 !== '3'
4 !== 3
```
In order, these expressions would evaluate to `false`, `true`, and `true`.
# --instructions--
Add the strict inequality operator to the `if` statement so the function will return "Not Equal" when `val` is not strictly equal to `17`
Add the strict inequality operator to the `if` statement so the function will return the string `Not Equal` when `val` is not strictly equal to `17`
# --hints--
`testStrictNotEqual(17)` should return "Equal"
`testStrictNotEqual(17)` should return the string `Equal`
```js
assert(testStrictNotEqual(17) === 'Equal');
```
`testStrictNotEqual("17")` should return "Not Equal"
`testStrictNotEqual("17")` should return the string `Not Equal`
```js
assert(testStrictNotEqual('17') === 'Not Equal');
```
`testStrictNotEqual(12)` should return "Not Equal"
`testStrictNotEqual(12)` should return the string `Not Equal`
```js
assert(testStrictNotEqual(12) === 'Not Equal');
```
`testStrictNotEqual("bob")` should return "Not Equal"
`testStrictNotEqual("bob")` should return the string `Not Equal`
```js
assert(testStrictNotEqual('bob') === 'Not Equal');

View File

@ -22,7 +22,7 @@ if (num > 5) {
return "No";
```
will only return "Yes" if `num` is greater than `5` and less than `10`. The same logic can be written as:
will only return `Yes` if `num` is greater than `5` and less than `10`. The same logic can be written as:
```js
if (num > 5 && num < 10) {
@ -33,7 +33,7 @@ return "No";
# --instructions--
Replace the two if statements with one statement, using the && operator, which will return `"Yes"` if `val` is less than or equal to `50` and greater than or equal to `25`. Otherwise, will return `"No"`.
Replace the two if statements with one statement, using the `&&` operator, which will return the string `Yes` if `val` is less than or equal to `50` and greater than or equal to `25`. Otherwise, will return the string `No`.
# --hints--
@ -49,49 +49,49 @@ You should only have one `if` statement
assert(code.match(/if/g).length === 1);
```
`testLogicalAnd(0)` should return "No"
`testLogicalAnd(0)` should return the string `No`
```js
assert(testLogicalAnd(0) === 'No');
```
`testLogicalAnd(24)` should return "No"
`testLogicalAnd(24)` should return the string `No`
```js
assert(testLogicalAnd(24) === 'No');
```
`testLogicalAnd(25)` should return "Yes"
`testLogicalAnd(25)` should return the string `Yes`
```js
assert(testLogicalAnd(25) === 'Yes');
```
`testLogicalAnd(30)` should return "Yes"
`testLogicalAnd(30)` should return the string `Yes`
```js
assert(testLogicalAnd(30) === 'Yes');
```
`testLogicalAnd(50)` should return "Yes"
`testLogicalAnd(50)` should return the string `Yes`
```js
assert(testLogicalAnd(50) === 'Yes');
```
`testLogicalAnd(51)` should return "No"
`testLogicalAnd(51)` should return the string `No`
```js
assert(testLogicalAnd(51) === 'No');
```
`testLogicalAnd(75)` should return "No"
`testLogicalAnd(75)` should return the string `No`
```js
assert(testLogicalAnd(75) === 'No');
```
`testLogicalAnd(80)` should return "No"
`testLogicalAnd(80)` should return the string `No`
```js
assert(testLogicalAnd(80) === 'No');

View File

@ -25,7 +25,7 @@ if (num < 5) {
return "Yes";
```
will return "Yes" only if `num` is between `5` and `10` (5 and 10 included). The same logic can be written as:
will return `Yes` only if `num` is between `5` and `10` (5 and 10 included). The same logic can be written as:
```js
if (num > 10 || num < 5) {
@ -36,7 +36,7 @@ return "Yes";
# --instructions--
Combine the two `if` statements into one statement which returns `"Outside"` if `val` is not between `10` and `20`, inclusive. Otherwise, return `"Inside"`.
Combine the two `if` statements into one statement which returns the string `Outside` if `val` is not between `10` and `20`, inclusive. Otherwise, return the string `Inside`.
# --hints--
@ -52,49 +52,49 @@ You should only have one `if` statement
assert(code.match(/if/g).length === 1);
```
`testLogicalOr(0)` should return "Outside"
`testLogicalOr(0)` should return the string `Outside`
```js
assert(testLogicalOr(0) === 'Outside');
```
`testLogicalOr(9)` should return "Outside"
`testLogicalOr(9)` should return the string `Outside`
```js
assert(testLogicalOr(9) === 'Outside');
```
`testLogicalOr(10)` should return "Inside"
`testLogicalOr(10)` should return the string `Inside`
```js
assert(testLogicalOr(10) === 'Inside');
```
`testLogicalOr(15)` should return "Inside"
`testLogicalOr(15)` should return the string `Inside`
```js
assert(testLogicalOr(15) === 'Inside');
```
`testLogicalOr(19)` should return "Inside"
`testLogicalOr(19)` should return the string `Inside`
```js
assert(testLogicalOr(19) === 'Inside');
```
`testLogicalOr(20)` should return "Inside"
`testLogicalOr(20)` should return the string `Inside`
```js
assert(testLogicalOr(20) === 'Inside');
```
`testLogicalOr(21)` should return "Outside"
`testLogicalOr(21)` should return the string `Outside`
```js
assert(testLogicalOr(21) === 'Outside');
```
`testLogicalOr(25)` should return "Outside"
`testLogicalOr(25)` should return the string `Outside`
```js
assert(testLogicalOr(25) === 'Outside');

View File

@ -20,9 +20,11 @@ One such operator is the `+=` operator.
```js
var myVar = 1;
myVar += 5;
console.log(myVar); // Returns 6
console.log(myVar);
```
`6` would be displayed in the console.
# --instructions--
Convert the assignments for `a`, `b`, and `c` to use the `+=` operator.

View File

@ -17,23 +17,22 @@ In JavaScript, when the `+` operator is used with a `String` value, it is called
'My name is Alan,' + ' I concatenate.'
```
**Note**
Watch out for spaces. Concatenation does not add spaces between concatenated strings, so you'll need to add them yourself.
**Note:** Watch out for spaces. Concatenation does not add spaces between concatenated strings, so you'll need to add them yourself.
Example:
```js
var ourStr = "I come first. " + "I come second.";
// ourStr is "I come first. I come second."
```
The string `I come first. I come second.` would be displayed in the console.
# --instructions--
Build `myStr` from the strings `"This is the start. "` and `"This is the end."` using the `+` operator.
Build `myStr` from the strings `This is the start. ` and `This is the end.` using the `+` operator.
# --hints--
`myStr` should have a value of `This is the start. This is the end.`
`myStr` should have a value of the string `This is the start. This is the end.`
```js
assert(myStr === 'This is the start. This is the end.');

View File

@ -11,24 +11,24 @@ dashedName: concatenating-strings-with-the-plus-equals-operator
We can also use the `+=` operator to <dfn>concatenate</dfn> a string onto the end of an existing string variable. This can be very helpful to break a long string over several lines.
**Note**
Watch out for spaces. Concatenation does not add spaces between concatenated strings, so you'll need to add them yourself.
**Note:** Watch out for spaces. Concatenation does not add spaces between concatenated strings, so you'll need to add them yourself.
Example:
```js
var ourStr = "I come first. ";
ourStr += "I come second.";
// ourStr is now "I come first. I come second."
```
`ourStr` now has a value of the string `I come first. I come second.`.
# --instructions--
Build `myStr` over several lines by concatenating these two strings: `"This is the first sentence. "` and `"This is the second sentence."` using the `+=` operator. Use the `+=` operator similar to how it is shown in the editor. Start by assigning the first string to `myStr`, then add on the second string.
Build `myStr` over several lines by concatenating these two strings: `This is the first sentence. ` and `This is the second sentence.` using the `+=` operator. Use the `+=` operator similar to how it is shown in the editor. Start by assigning the first string to `myStr`, then add on the second string.
# --hints--
`myStr` should have a value of `This is the first sentence. This is the second sentence.`
`myStr` should have a value of the string `This is the first sentence. This is the second sentence.`
```js
assert(myStr === 'This is the first sentence. This is the second sentence.');

View File

@ -16,12 +16,13 @@ Example:
```js
var ourName = "freeCodeCamp";
var ourStr = "Hello, our name is " + ourName + ", how are you?";
// ourStr is now "Hello, our name is freeCodeCamp, how are you?"
```
`ourStr` would have a value of the string `Hello, our name is freeCodeCamp, how are you?`.
# --instructions--
Set `myName` to a string equal to your name and build `myStr` with `myName` between the strings `"My name is "` and `" and I am well!"`
Set `myName` to a string equal to your name and build `myStr` with `myName` between the strings `My name is ` and ` and I am well!`
# --hints--

View File

@ -11,7 +11,7 @@ dashedName: count-backwards-with-a-for-loop
A for loop can also count backwards, so long as we can define the right conditions.
In order to decrement by two each iteration, we'll need to change our `initialization`, `condition`, and `final-expression`.
In order to decrement by two each iteration, we'll need to change our initialization, condition, and final expression.
We'll start at `i = 10` and loop while `i > 0`. We'll decrement `i` by 2 each loop with `i -= 2`.
@ -22,7 +22,7 @@ for (var i = 10; i > 0; i -= 2) {
}
```
`ourArray` will now contain `[10,8,6,4,2]`. Let's change our `initialization` and `final-expression` so we can count backward by twos by odd numbers.
`ourArray` will now contain `[10,8,6,4,2]`. Let's change our initialization and final expression so we can count backward by twos by odd numbers.
# --instructions--

View File

@ -47,7 +47,7 @@ assert(
);
```
Cards Sequence 7, 8, 9 should return `0 Hold`
Cards Sequence 7, 8, 9 should return the string `0 Hold`
```js
assert(
@ -64,7 +64,7 @@ assert(
);
```
Cards Sequence 10, J, Q, K, A should return `-5 Hold`
Cards Sequence 10, J, Q, K, A should return the string `-5 Hold`
```js
assert(
@ -83,7 +83,7 @@ assert(
);
```
Cards Sequence 3, 7, Q, 8, A should return `-1 Hold`
Cards Sequence 3, 7, Q, 8, A should return the string `-1 Hold`
```js
assert(
@ -102,7 +102,7 @@ assert(
);
```
Cards Sequence 2, J, 9, 2, 7 should return `1 Bet`
Cards Sequence 2, J, 9, 2, 7 should return the string `1 Bet`
```js
assert(
@ -121,7 +121,7 @@ assert(
);
```
Cards Sequence 2, 2, 10 should return `1 Bet`
Cards Sequence 2, 2, 10 should return the string `1 Bet`
```js
assert(
@ -138,7 +138,7 @@ assert(
);
```
Cards Sequence 3, 2, A, 10, K should return `-1 Hold`
Cards Sequence 3, 2, A, 10, K should return the string `-1 Hold`
```js
assert(

View File

@ -11,8 +11,7 @@ dashedName: create-decimal-numbers-with-javascript
We can store decimal numbers in variables too. Decimal numbers are sometimes referred to as <dfn>floating point</dfn> numbers or <dfn>floats</dfn>.
**Note**
Not all real numbers can accurately be represented in <dfn>floating point</dfn>. This can lead to rounding errors. [Details Here](https://en.wikipedia.org/wiki/Floating_point#Accuracy_problems).
**Note:** Not all real numbers can accurately be represented in <dfn>floating point</dfn>. This can lead to rounding errors. [Details Here](https://en.wikipedia.org/wiki/Floating_point#Accuracy_problems).
# --instructions--

View File

@ -17,7 +17,7 @@ Previously we have used the code
# --instructions--
Create two new `string` variables: `myFirstName` and `myLastName` and assign them the values of your first and last name, respectively.
Create two new string variables: `myFirstName` and `myLastName` and assign them the values of your first and last name, respectively.
# --hints--

View File

@ -17,8 +17,7 @@ is the equivalent of
`i = i - 1;`
**Note**
The entire line becomes `i--;`, eliminating the need for the equal sign.
**Note:** The entire line becomes `i--;`, eliminating the need for the equal sign.
# --instructions--

View File

@ -40,11 +40,11 @@ After the last line shown above, `ourDog` looks like:
# --instructions--
Delete the `"tails"` property from `myDog`. You may use either dot or bracket notation.
Delete the `tails` property from `myDog`. You may use either dot or bracket notation.
# --hints--
You should delete the property `"tails"` from `myDog`.
You should delete the property `tails` from `myDog`.
```js
assert(typeof myDog === 'object' && myDog.tails === undefined);

View File

@ -16,9 +16,10 @@ JavaScript uses the `/` symbol for division.
**Example**
```js
myVar = 16 / 2; // assigned 8
myVar = 16 / 2;
```
`myVar` now has the value `8`.
# --instructions--
Change the `0` so that the `quotient` is equal to `2`.

View File

@ -11,9 +11,13 @@ dashedName: find-the-length-of-a-string
You can find the length of a `String` value by writing `.length` after the string variable or string literal.
`"Alan Peter".length; // 10`
```js
console.log("Alan Peter".length);
```
For example, if we created a variable `var firstName = "Charles"`, we could find out how long the string `"Charles"` is by using the `firstName.length` property.
The value `10` would be displayed in the console.
For example, if we created a variable `var firstName = "Charles"`, we could find out how long the string `Charles` is by using the `firstName.length` property.
# --instructions--

View File

@ -20,8 +20,7 @@ In mathematics, a number can be checked to be even or odd by checking the remain
<blockquote>17 % 2 = 1 (17 is Odd)<br>48 % 2 = 0 (48 is Even)</blockquote>
**Note**
The <dfn>remainder</dfn> operator is sometimes incorrectly referred to as the "modulus" operator. It is very similar to modulus, but does not work properly with negative numbers.
**Note:** The <dfn>remainder</dfn> operator is sometimes incorrectly referred to as the modulus operator. It is very similar to modulus, but does not work properly with negative numbers.
# --instructions--

View File

@ -13,8 +13,7 @@ Random numbers are useful for creating random behavior.
JavaScript has a `Math.random()` function that generates a random decimal number between `0` (inclusive) and not quite up to `1` (exclusive). Thus `Math.random()` can return a `0` but never quite return a `1`
**Note**
Like [Storing Values with the Equal Operator](/learn/javascript-algorithms-and-data-structures/basic-javascript/storing-values-with-the-assignment-operator), all function calls will be resolved before the `return` executes, so we can `return` the value of the `Math.random()` function.
**Note:** Like [Storing Values with the Equal Operator](/learn/javascript-algorithms-and-data-structures/basic-javascript/storing-values-with-the-assignment-operator), all function calls will be resolved before the `return` executes, so we can `return` the value of the `Math.random()` function.
# --instructions--

View File

@ -21,11 +21,11 @@ function myFun() {
}
```
The function `myFun` will return `"Head"` because the `local` version of the variable is present.
The function `myFun` will return the string `Head` because the `local` version of the variable is present.
# --instructions--
Add a local variable to `myOutfit` function to override the value of `outerWear` with `"sweater"`.
Add a local variable to `myOutfit` function to override the value of `outerWear` with the string `sweater`.
# --hints--
@ -35,7 +35,7 @@ You should not change the value of the global `outerWear`.
assert(outerWear === 'T-Shirt');
```
`myOutfit` should return `"sweater"`.
`myOutfit` should return the string `sweater`.
```js
assert(myOutfit() === 'sweater');

View File

@ -19,67 +19,67 @@ Your function will be passed `par` and `strokes` arguments. Return the correct s
# --hints--
`golfScore(4, 1)` should return "Hole-in-one!"
`golfScore(4, 1)` should return the string `Hole-in-one!`
```js
assert(golfScore(4, 1) === 'Hole-in-one!');
```
`golfScore(4, 2)` should return "Eagle"
`golfScore(4, 2)` should return the string `Eagle`
```js
assert(golfScore(4, 2) === 'Eagle');
```
`golfScore(5, 2)` should return "Eagle"
`golfScore(5, 2)` should return the string `Eagle`
```js
assert(golfScore(5, 2) === 'Eagle');
```
`golfScore(4, 3)` should return "Birdie"
`golfScore(4, 3)` should return the string `Birdie`
```js
assert(golfScore(4, 3) === 'Birdie');
```
`golfScore(4, 4)` should return "Par"
`golfScore(4, 4)` should return the string `Par`
```js
assert(golfScore(4, 4) === 'Par');
```
`golfScore(1, 1)` should return "Hole-in-one!"
`golfScore(1, 1)` should return the string `Hole-in-one!`
```js
assert(golfScore(1, 1) === 'Hole-in-one!');
```
`golfScore(5, 5)` should return "Par"
`golfScore(5, 5)` should return the string `Par`
```js
assert(golfScore(5, 5) === 'Par');
```
`golfScore(4, 5)` should return "Bogey"
`golfScore(4, 5)` should return the string `Bogey`
```js
assert(golfScore(4, 5) === 'Bogey');
```
`golfScore(4, 6)` should return "Double Bogey"
`golfScore(4, 6)` should return the string `Double Bogey`
```js
assert(golfScore(4, 6) === 'Double Bogey');
```
`golfScore(4, 7)` should return "Go Home!"
`golfScore(4, 7)` should return the string `Go Home!`
```js
assert(golfScore(4, 7) === 'Go Home!');
```
`golfScore(5, 9)` should return "Go Home!"
`golfScore(5, 9)` should return the string `Go Home!`
```js
assert(golfScore(5, 9) === 'Go Home!');

View File

@ -17,8 +17,7 @@ is the equivalent of
`i = i + 1;`
**Note**
The entire line becomes `i++;`, eliminating the need for the equal sign.
**Note:** The entire line becomes `i++;`, eliminating the need for the equal sign.
# --instructions--

View File

@ -49,31 +49,31 @@ assert(
);
```
`testElseIf(0)` should return "Smaller than 5"
`testElseIf(0)` should return the string `Smaller than 5`
```js
assert(testElseIf(0) === 'Smaller than 5');
```
`testElseIf(5)` should return "Between 5 and 10"
`testElseIf(5)` should return the string `Between 5 and 10`
```js
assert(testElseIf(5) === 'Between 5 and 10');
```
`testElseIf(7)` should return "Between 5 and 10"
`testElseIf(7)` should return the string `Between 5 and 10`
```js
assert(testElseIf(7) === 'Between 5 and 10');
```
`testElseIf(10)` should return "Between 5 and 10"
`testElseIf(10)` should return the string `Between 5 and 10`
```js
assert(testElseIf(10) === 'Between 5 and 10');
```
`testElseIf(12)` should return "Greater than 10"
`testElseIf(12)` should return the string `Greater than 10`
```js
assert(testElseIf(12) === 'Greater than 10');

View File

@ -37,25 +37,25 @@ You should use an `else` statement
assert(/else/g.test(code));
```
`testElse(4)` should return "5 or Smaller"
`testElse(4)` should return the string `5 or Smaller`
```js
assert(testElse(4) === '5 or Smaller');
```
`testElse(5)` should return "5 or Smaller"
`testElse(5)` should return the string `5 or Smaller`
```js
assert(testElse(5) === '5 or Smaller');
```
`testElse(6)` should return "Bigger than 5"
`testElse(6)` should return the string `Bigger than 5`
```js
assert(testElse(6) === 'Bigger than 5');
```
`testElse(10)` should return "Bigger than 5".
`testElse(10)` should return the string `Bigger than 5`
```js
assert(testElse(10) === 'Bigger than 5');

View File

@ -11,19 +11,19 @@ dashedName: iterate-with-javascript-for-loops
You can run the same code multiple times by using a loop.
The most common type of JavaScript loop is called a `for` loop because it runs "for" a specific number of times.
The most common type of JavaScript loop is called a `for` loop because it runs for a specific number of times.
For loops are declared with three optional expressions separated by semicolons:
`for ([initialization]; [condition]; [final-expression])`
`for (a; b; c)`, where `a` is the intialization statement, `b` is the condition statement, and `c` is the final expression.
The `initialization` statement is executed one time only before the loop starts. It is typically used to define and setup your loop variable.
The initialization statement is executed one time only before the loop starts. It is typically used to define and setup your loop variable.
The `condition` statement is evaluated at the beginning of every loop iteration and will continue as long as it evaluates to `true`. When `condition` is `false` at the start of the iteration, the loop will stop executing. This means if `condition` starts as `false`, your loop will never execute.
The condition statement is evaluated at the beginning of every loop iteration and will continue as long as it evaluates to `true`. When the condition is `false` at the start of the iteration, the loop will stop executing. This means if the condition starts as false, your loop will never execute.
The `final-expression` is executed at the end of each loop iteration, prior to the next `condition` check and is usually used to increment or decrement your loop counter.
The final expression is executed at the end of each loop iteration, prior to the next condition check and is usually used to increment or decrement your loop counter.
In the following example we initialize with `i = 0` and iterate while our condition `i < 5` is true. We'll increment `i` by `1` in each loop iteration with `i++` as our `final-expression`.
In the following example we initialize with `i = 0` and iterate while our condition `i < 5` is true. We'll increment `i` by `1` in each loop iteration with `i++` as our final expression.
```js
var ourArray = [];
@ -32,11 +32,11 @@ for (var i = 0; i < 5; i++) {
}
```
`ourArray` will now contain `[0,1,2,3,4]`.
`ourArray` will now have the value `[0,1,2,3,4]`.
# --instructions--
Use a `for` loop to work to push the values 1 through 5 onto `myArray`.
Use a `for` loop to push the values 1 through 5 onto `myArray`.
# --hints--

View File

@ -11,7 +11,7 @@ dashedName: iterate-with-javascript-while-loops
You can run the same code multiple times by using a loop.
The first type of loop we will learn is called a `while` loop because it runs "while" a specified condition is true and stops once that condition is no longer true.
The first type of loop we will learn is called a `while` loop because it runs while a specified condition is true and stops once that condition is no longer true.
```js
var ourArray = [];

View File

@ -9,7 +9,7 @@ dashedName: local-scope-and-functions
# --description--
Variables which are declared within a function, as well as the function parameters have <dfn>local</dfn> scope. That means, they are only visible within that function.
Variables which are declared within a function, as well as the function parameters, have <dfn>local</dfn> scope. That means they are only visible within that function.
Here is a function `myTest` with a local variable called `loc`.
@ -18,17 +18,17 @@ function myTest() {
var loc = "foo";
console.log(loc);
}
myTest(); // logs "foo"
console.log(loc); // loc is not defined
myTest();
console.log(loc);
```
`loc` is not defined outside of the function.
The `myTest()` function call will display the string `foo` in the console. The `console.log(loc)` line will throw an error, as `loc` is not defined outside of the function.
# --instructions--
The editor has two `console.log`s to help you see what is happening. Check the console as you code to see how it changes. Declare a local variable `myVar` inside `myLocalScope` and run the tests.
**Note:** The console will still have 'ReferenceError: myVar is not defined', but this will not cause the tests to fail.
**Note:** The console will still display `ReferenceError: myVar is not defined`, but this will not cause the tests to fail.
# --hints--

View File

@ -46,29 +46,31 @@ function bar(x) {
While these two functions look nearly identical if we pass a number to both we get different outputs.
```js
foo(0) // "Less than one"
bar(0) // "Less than two"
foo(0)
bar(0)
```
`foo(0)` will return the string `Less than one`, and `bar(0)` will return the string `Less than two`.
# --instructions--
Change the order of logic in the function so that it will return the correct statements in all cases.
# --hints--
`orderMyLogic(4)` should return "Less than 5"
`orderMyLogic(4)` should return the string `Less than 5`
```js
assert(orderMyLogic(4) === 'Less than 5');
```
`orderMyLogic(6)` should return "Less than 10"
`orderMyLogic(6)` should return the string `Less than 10`
```js
assert(orderMyLogic(6) === 'Less than 10');
```
`orderMyLogic(11)` should return "Greater than or equal to 10"
`orderMyLogic(11)` should return the string `Greater than or equal to 10`
```js
assert(orderMyLogic(11) === 'Greater than or equal to 10');

View File

@ -11,20 +11,22 @@ dashedName: manipulate-arrays-with-pop
Another way to change the data in an array is with the `.pop()` function.
`.pop()` is used to "pop" a value off of the end of an array. We can store this "popped off" value by assigning it to a variable. In other words, `.pop()` removes the last element from an array and returns that element.
`.pop()` is used to pop a value off of the end of an array. We can store this popped off value by assigning it to a variable. In other words, `.pop()` removes the last element from an array and returns that element.
Any type of entry can be "popped" off of an array - numbers, strings, even nested arrays.
Any type of entry can be popped off of an array - numbers, strings, even nested arrays.
```js
var threeArr = [1, 4, 6];
var oneDown = threeArr.pop();
console.log(oneDown); // Returns 6
console.log(threeArr); // Returns [1, 4]
console.log(oneDown);
console.log(threeArr);
```
The first `console.log` will display the value `6`, and the second will display the value `[1, 4]`.
# --instructions--
Use the `.pop()` function to remove the last item from `myArray`, assigning the "popped off" value to `removedFromMyArray`.
Use the `.pop()` function to remove the last item from `myArray`, assigning the popped off value to `removedFromMyArray`.
# --hints--

View File

@ -18,13 +18,13 @@ Examples:
```js
var arr1 = [1,2,3];
arr1.push(4);
// arr1 is now [1,2,3,4]
var arr2 = ["Stimpson", "J", "cat"];
arr2.push(["happy", "joy"]);
// arr2 now equals ["Stimpson", "J", "cat", ["happy", "joy"]]
```
`arr1` now has the value `[1, 2, 3, 4]` and `arr2` has the value `["Stimpson", "J", "cat", ["happy", "joy"]]`.
# --instructions--
Push `["dog", 3]` onto the end of the `myArray` variable.

View File

@ -18,9 +18,10 @@ Example:
```js
var ourArray = ["Stimpson", "J", ["cat"]];
var removedFromOurArray = ourArray.shift();
// removedFromOurArray now equals "Stimpson" and ourArray now equals ["J", ["cat"]].
```
`removedFromOurArray` would have a value of the string `Stimpson`, and `ourArray` would have `["J", ["cat"]]`.
# --instructions--
Use the `.shift()` function to remove the first item from `myArray`, assigning the "shifted off" value to `removedFromMyArray`.

View File

@ -17,11 +17,12 @@ Example:
```js
var ourArray = ["Stimpson", "J", "cat"];
ourArray.shift(); // ourArray now equals ["J", "cat"]
ourArray.shift();
ourArray.unshift("Happy");
// ourArray now equals ["Happy", "J", "cat"]
```
After the `shift`, `ourArray` would have the value `["J", "cat"]`. After the `unshift`, `ourArray` would have the value `["Happy", "J", "cat"]`.
# --instructions--
Add `["Paul",35]` to the beginning of the `myArray` variable using `unshift()`.

View File

@ -29,7 +29,7 @@ var ourMusic = [
];
```
This is an array which contains one object inside. The object has various pieces of <dfn>metadata</dfn> about an album. It also has a nested `"formats"` array. If you want to add more album records, you can do this by adding records to the top level array. Objects hold data in a property, which has a key-value format. In the example above, `"artist": "Daft Punk"` is a property that has a key of `"artist"` and a value of `"Daft Punk"`. [JavaScript Object Notation](http://www.json.org/) or `JSON` is a related data interchange format used to store data.
This is an array which contains one object inside. The object has various pieces of <dfn>metadata</dfn> about an album. It also has a nested `formats` array. If you want to add more album records, you can do this by adding records to the top level array. Objects hold data in a property, which has a key-value format. In the example above, `"artist": "Daft Punk"` is a property that has a key of `artist` and a value of `Daft Punk`. [JavaScript Object Notation](http://www.json.org/) or `JSON` is a related data interchange format used to store data.
```json
{
@ -45,8 +45,7 @@ This is an array which contains one object inside. The object has various pieces
}
```
**Note**
You will need to place a comma after every object in the array, unless it is the last object in the array.
**Note:** You will need to place a comma after every object in the array, unless it is the last object in the array.
# --instructions--

View File

@ -15,11 +15,12 @@ Unlike strings, the entries of arrays are <dfn>mutable</dfn> and can be changed
```js
var ourArray = [50,40,30];
ourArray[0] = 15; // equals [15,40,30]
ourArray[0] = 15;
```
**Note**
There shouldn't be any spaces between the array name and the square brackets, like `array [0]`. Although JavaScript is able to process this correctly, this may confuse other programmers reading your code.
`ourArray` now has the value `[15, 40, 30]`.
**Note:** There shouldn't be any spaces between the array name and the square brackets, like `array [0]`. Although JavaScript is able to process this correctly, this may confuse other programmers reading your code.
# --instructions--
@ -27,7 +28,7 @@ Modify the data stored at index `0` of `myArray` to a value of `45`.
# --hints--
`myArray` should now be [45,64,99].
`myArray` should now be `[45,64,99]`.
```js
assert(

View File

@ -29,64 +29,63 @@ Cases for 1, 2, and 3 will all produce the same result.
# --instructions--
Write a switch statement to set `answer` for the following ranges:
`1-3` - "Low"
`4-6` - "Mid"
`7-9` - "High"
`1-3` - `Low`
`4-6` - `Mid`
`7-9` - `High`
**Note**
You will need to have a `case` statement for each number in the range.
**Note:** You will need to have a `case` statement for each number in the range.
# --hints--
`sequentialSizes(1)` should return "Low"
`sequentialSizes(1)` should return the string `Low`
```js
assert(sequentialSizes(1) === 'Low');
```
`sequentialSizes(2)` should return "Low"
`sequentialSizes(2)` should return the string `Low`
```js
assert(sequentialSizes(2) === 'Low');
```
`sequentialSizes(3)` should return "Low"
`sequentialSizes(3)` should return the string `Low`
```js
assert(sequentialSizes(3) === 'Low');
```
`sequentialSizes(4)` should return "Mid"
`sequentialSizes(4)` should return the string `Mid`
```js
assert(sequentialSizes(4) === 'Mid');
```
`sequentialSizes(5)` should return "Mid"
`sequentialSizes(5)` should return the string `Mid`
```js
assert(sequentialSizes(5) === 'Mid');
```
`sequentialSizes(6)` should return "Mid"
`sequentialSizes(6)` should return the string `Mid`
```js
assert(sequentialSizes(6) === 'Mid');
```
`sequentialSizes(7)` should return "High"
`sequentialSizes(7)` should return the string `High`
```js
assert(sequentialSizes(7) === 'High');
```
`sequentialSizes(8)` should return "High"
`sequentialSizes(8)` should return the string `High`
```js
assert(sequentialSizes(8) === 'High');
```
`sequentialSizes(9)` should return "High"
`sequentialSizes(9)` should return the string `High`
```js
assert(sequentialSizes(9) === 'High');

View File

@ -16,9 +16,11 @@ JavaScript uses the `*` symbol for multiplication of two numbers.
**Example**
```js
myVar = 13 * 13; // assigned 169
myVar = 13 * 13;
```
`myVar` would have the value `169`.
# --instructions--
Change the `0` so that product will equal `80`.

View File

@ -15,32 +15,30 @@ If the values being compared are not of the same type, the equality operator wil
**Examples**
```js
3 == '3' // returns true because JavaScript performs type conversion from string to number
3 === '3' // returns false because the types are different and type conversion is not performed
```
`3 == '3'` returns `true` because JavaScript performs type conversion from string to number. `3 === '3'` returns false because the types are different and type conversion is not performed.
**Note**
In JavaScript, you can determine the type of a variable or a value with the `typeof` operator, as follows:
**Note:** In JavaScript, you can determine the type of a variable or a value with the `typeof` operator, as follows:
```js
typeof 3 // returns 'number'
typeof '3' // returns 'string'
typeof 3
typeof '3'
```
`typeof 3` returns the string `number`, and `typeof '3'` returns the string `string`.
# --instructions--
The `compareEquality` function in the editor compares two values using the equality operator. Modify the function so that it returns "Equal" only when the values are strictly equal.
The `compareEquality` function in the editor compares two values using the equality operator. Modify the function so that it returns the string `Equal` only when the values are strictly equal.
# --hints--
`compareEquality(10, "10")` should return "Not Equal"
`compareEquality(10, "10")` should return the string `Not Equal`
```js
assert(compareEquality(10, '10') === 'Not Equal');
```
`compareEquality("20", 20)` should return "Not Equal"
`compareEquality("20", 20)` should return the string `Not Equal`
```js
assert(compareEquality('20', 20) === 'Not Equal');

View File

@ -17,13 +17,13 @@ The function should check if `name` is an actual contact's `firstName` and the g
If both are true, then return the "value" of that property.
If `name` does not correspond to any contacts then return `"No such contact"`.
If `name` does not correspond to any contacts then return the string `No such contact`.
If `prop` does not correspond to any valid properties of a contact found to match `name` then return `"No such property"`.
If `prop` does not correspond to any valid properties of a contact found to match `name` then return the string `No such property`.
# --hints--
`lookUpProfile("Kristian", "lastName")` should return `"Vos"`
`lookUpProfile("Kristian", "lastName")` should return the string `Vos`
```js
assert(lookUpProfile('Kristian', 'lastName') === 'Vos');
@ -44,19 +44,19 @@ assert.deepEqual(lookUpProfile('Sherlock', 'likes'), [
assert(typeof lookUpProfile('Harry', 'likes') === 'object');
```
`lookUpProfile("Bob", "number")` should return "No such contact"
`lookUpProfile("Bob", "number")` should return the string `No such contact`
```js
assert(lookUpProfile('Bob', 'number') === 'No such contact');
```
`lookUpProfile("Bob", "potato")` should return "No such contact"
`lookUpProfile("Bob", "potato")` should return the string `No such contact`
```js
assert(lookUpProfile('Bob', 'potato') === 'No such contact');
```
`lookUpProfile("Akira", "address")` should return "No such property"
`lookUpProfile("Akira", "address")` should return the string `No such property`
```js
assert(lookUpProfile('Akira', 'address') === 'No such property');

View File

@ -26,12 +26,14 @@ However, this becomes a problem if you need to use the outermost quotes within i
```js
goodStr = 'Jake asks Finn, "Hey, let\'s go on an adventure?"';
badStr = 'Finn responds, "Let's go!"'; // Throws an error
badStr = 'Finn responds, "Let's go!"';
```
In the <dfn>goodStr</dfn> above, you can use both quotes safely by using the backslash <code>\\</code> as an escape character.
Here `badStr` will throw an error.
**Note:** The backslash <code>\\</code> should not be confused with the forward slash `/`. They do not do the same thing.
In the <dfn>goodStr</dfn> above, you can use both quotes safely by using the backslash `\` as an escape character.
**Note:** The backslash `\` should not be confused with the forward slash `/`. They do not do the same thing.
# --instructions--

View File

@ -22,7 +22,7 @@ You start with an `updateRecords` function that takes an object like `collection
# --hints--
After `updateRecords(collection, 5439, "artist", "ABBA")`, `artist` should be `ABBA`
After `updateRecords(collection, 5439, "artist", "ABBA")`, `artist` should be the string `ABBA`
```js
assert(
@ -31,7 +31,7 @@ assert(
);
```
After `updateRecords(collection, 5439, "tracks", "Take a Chance on Me")`, `tracks` should have `Take a Chance on Me` as the last element.
After `updateRecords(collection, 5439, "tracks", "Take a Chance on Me")`, `tracks` should have the string `Take a Chance on Me` as the last element.
```js
assert(
@ -48,7 +48,7 @@ updateRecords(_recordCollection, 2548, 'artist', '');
assert(!_recordCollection[2548].hasOwnProperty('artist'));
```
After `updateRecords(collection, 1245, "tracks", "Addicted to Love")`, `tracks` should have `Addicted to Love` as the last element.
After `updateRecords(collection, 1245, "tracks", "Addicted to Love")`, `tracks` should have the string `Addicted to Love` as the last element.
```js
assert(
@ -58,7 +58,7 @@ assert(
);
```
After `updateRecords(collection, 2468, "tracks", "Free")`, `tracks` should have `1999` as the first element.
After `updateRecords(collection, 2468, "tracks", "Free")`, `tracks` should have the string `1999` as the first element.
```js
assert(
@ -75,7 +75,7 @@ updateRecords(_recordCollection, 2548, 'tracks', '');
assert(!_recordCollection[2548].hasOwnProperty('tracks'));
```
After `updateRecords(collection, 1245, "albumTitle", "Riptide")`, `albumTitle` should be `Riptide`
After `updateRecords(collection, 1245, "albumTitle", "Riptide")`, `albumTitle` should be the string `Riptide`
```js
assert(

View File

@ -60,43 +60,43 @@ You should have at least four `break` statements
assert(code.match(/break/g).length >= 4);
```
`chainToSwitch("bob")` should be "Marley"
`chainToSwitch("bob")` should be the string `Marley`
```js
assert(chainToSwitch('bob') === 'Marley');
```
`chainToSwitch(42)` should be "The Answer"
`chainToSwitch(42)` should be the string `The Answer`
```js
assert(chainToSwitch(42) === 'The Answer');
```
`chainToSwitch(1)` should be "There is no #1"
`chainToSwitch(1)` should be the string `There is no #1`
```js
assert(chainToSwitch(1) === 'There is no #1');
```
`chainToSwitch(99)` should be "Missed me by this much!"
`chainToSwitch(99)` should be the string `Missed me by this much!`
```js
assert(chainToSwitch(99) === 'Missed me by this much!');
```
`chainToSwitch(7)` should be "Ate Nine"
`chainToSwitch(7)` should be the string `Ate Nine`
```js
assert(chainToSwitch(7) === 'Ate Nine');
```
`chainToSwitch("John")` should be "" (empty string)
`chainToSwitch("John")` should be `""` (empty string)
```js
assert(chainToSwitch('John') === '');
```
`chainToSwitch(156)` should be "" (empty string)
`chainToSwitch(156)` should be `""` (empty string)
```js
assert(chainToSwitch(156) === '');

View File

@ -17,9 +17,11 @@ We can pass values into a function with <dfn>arguments</dfn>. You can use a `ret
function plusThree(num) {
return num + 3;
}
var answer = plusThree(5); // 8
var answer = plusThree(5);
```
`answer` has the value `8`.
`plusThree` takes an <dfn>argument</dfn> for `num` and returns a value equal to `num + 3`.
# --instructions--

View File

@ -22,7 +22,7 @@ function myFun() {
myFun();
```
The above outputs "Hello" to the console, returns "World", but `"byebye"` is never output, because the function exits at the `return` statement.
The above will display the string `Hello` in the console, and return the string `World`. The string `byebye` will never display in the console, because the function exits at the `return` statement.
# --instructions--

View File

@ -11,7 +11,7 @@ dashedName: returning-boolean-values-from-functions
You may recall from [Comparison with the Equality Operator](/learn/javascript-algorithms-and-data-structures/basic-javascript/comparison-with-the-equality-operator) that all comparison operators return a boolean `true` or `false` value.
Sometimes people use an if/else statement to do a comparison, like this:
Sometimes people use an `if/else` statement to do a comparison, like this:
```js
function isEqual(a,b) {

View File

@ -29,32 +29,32 @@ switch(lowercaseLetter) {
# --instructions--
Write a switch statement which tests `val` and sets `answer` for the following conditions:
`1` - "alpha"
`2` - "beta"
`3` - "gamma"
`4` - "delta"
`1` - `alpha`
`2` - `beta`
`3` - `gamma`
`4` - `delta`
# --hints--
`caseInSwitch(1)` should have a value of "alpha"
`caseInSwitch(1)` should have a value of the string `alpha`
```js
assert(caseInSwitch(1) === 'alpha');
```
`caseInSwitch(2)` should have a value of "beta"
`caseInSwitch(2)` should have a value of the string `beta`
```js
assert(caseInSwitch(2) === 'beta');
```
`caseInSwitch(3)` should have a value of "gamma"
`caseInSwitch(3)` should have a value of the string `gamma`
```js
assert(caseInSwitch(3) === 'gamma');
```
`caseInSwitch(4)` should have a value of "delta"
`caseInSwitch(4)` should have a value of the string `delta`
```js
assert(caseInSwitch(4) === 'delta');

View File

@ -16,9 +16,10 @@ JavaScript uses the `-` symbol for subtraction.
**Example**
```js
myVar = 12 - 6; // assigned 6
myVar = 12 - 6;
```
`myVar` would have the value `6`.
# --instructions--
Change the `0` so the difference is `12`.

View File

@ -18,17 +18,19 @@ var myObj = {
top: "hat",
bottom: "pants"
};
myObj.hasOwnProperty("top"); // true
myObj.hasOwnProperty("middle"); // false
myObj.hasOwnProperty("top");
myObj.hasOwnProperty("middle");
```
The first `hasOwnProperty` returns `true`, while the second returns `false`.
# --instructions--
Modify the function `checkObj` to test if an object passed to the function (`obj`) contains a specific property (`checkProp`). If the property is found, return that property's value. If not, return `"Not Found"`.
# --hints--
`checkObj({gift: "pony", pet: "kitten", bed: "sleigh"}, "gift")` should return `"pony"`.
`checkObj({gift: "pony", pet: "kitten", bed: "sleigh"}, "gift")` should return the string `pony`.
```js
assert(
@ -36,7 +38,7 @@ assert(
);
```
`checkObj({gift: "pony", pet: "kitten", bed: "sleigh"}, "pet")` should return `"kitten"`.
`checkObj({gift: "pony", pet: "kitten", bed: "sleigh"}, "pet")` should return the string `kitten`.
```js
assert(
@ -44,7 +46,7 @@ assert(
);
```
`checkObj({gift: "pony", pet: "kitten", bed: "sleigh"}, "house")` should return `"Not Found"`.
`checkObj({gift: "pony", pet: "kitten", bed: "sleigh"}, "house")` should return the string `Not Found`.
```js
assert(
@ -53,19 +55,19 @@ assert(
);
```
`checkObj({city: "Seattle"}, "city")` should return `"Seattle"`.
`checkObj({city: "Seattle"}, "city")` should return the string `Seattle`.
```js
assert(checkObj({ city: 'Seattle' }, 'city') === 'Seattle');
```
`checkObj({city: "Seattle"}, "district")` should return `"Not Found"`.
`checkObj({city: "Seattle"}, "district")` should return the string `Not Found`.
```js
assert(checkObj({ city: 'Seattle' }, 'district') === 'Not Found');
```
`checkObj({pet: "kitten", bed: "sleigh"}, "gift")` should return `"Not Found"`.
`checkObj({pet: "kitten", bed: "sleigh"}, "gift")` should return the string `Not Found`.
```js
assert(checkObj({ pet: 'kitten', bed: 'sleigh' }, 'gift') === 'Not Found');

View File

@ -18,7 +18,7 @@ var myStr = "Bob";
myStr[0] = "J";
```
cannot change the value of `myStr` to "Job", because the contents of `myStr` cannot be altered. Note that this does *not* mean that `myStr` cannot be changed, just that the individual characters of a <dfn>string literal</dfn> cannot be changed. The only way to change `myStr` would be to assign it with a new string, like this:
cannot change the value of `myStr` to `Job`, because the contents of `myStr` cannot be altered. Note that this does *not* mean that `myStr` cannot be changed, just that the individual characters of a <dfn>string literal</dfn> cannot be changed. The only way to change `myStr` would be to assign it with a new string, like this:
```js
var myStr = "Bob";
@ -31,7 +31,7 @@ Correct the assignment to `myStr` so it contains the string value of `Hello Worl
# --hints--
`myStr` should have a value of `Hello World`.
`myStr` should have a value of the string `Hello World`.
```js
assert(myStr === 'Hello World');

View File

@ -9,10 +9,9 @@ dashedName: understanding-boolean-values
# --description--
Another data type is the <dfn>Boolean</dfn>. Booleans may only be one of two values: `true` or `false`. They are basically little on-off switches, where `true` is "on" and `false` is "off". These two states are mutually exclusive.
Another data type is the <dfn>Boolean</dfn>. Booleans may only be one of two values: `true` or `false`. They are basically little on-off switches, where `true` is on and `false` is off. These two states are mutually exclusive.
**Note**
Boolean values are never written with quotes. The strings `"true"` and `"false"` are not Boolean and have no special meaning in JavaScript.
**Note:** Boolean values are never written with quotes. The strings `"true"` and `"false"` are not Boolean and have no special meaning in JavaScript.
# --instructions--

View File

@ -27,7 +27,8 @@ var thisVariableNameIsSoLong;
# --instructions--
Modify the existing declarations and assignments so their names use <dfn>camelCase</dfn>.
Modify the existing declarations and assignments so their names use <dfn>camelCase</dfn>.
Do not create any new variables.
# --hints--
@ -38,7 +39,7 @@ Do not create any new variables.
assert(typeof studlyCapVar !== 'undefined' && studlyCapVar === 10);
```
`properCamelCase` should be defined and have a value of `"A String"`.
`properCamelCase` should be defined and have a value of the string `A String`.
```js
assert(

View File

@ -18,7 +18,7 @@ var sum = 0;
function addSum(num) {
sum = sum + num;
}
addSum(3); // sum will be modified but returned value is undefined
addSum(3);
```
`addSum` is a function without a `return` statement. The function will change the global `sum` variable but the returned value of the function is `undefined`.
@ -35,7 +35,7 @@ Create a function `addFive` without any arguments. This function adds 5 to the `
assert(typeof addFive === 'function');
```
Once both functions have ran, the `sum` should be equal to 8.
Once both functions have run, the `sum` should be equal to `8`.
```js
assert(sum === 8);

View File

@ -9,7 +9,7 @@ dashedName: understanding-uninitialized-variables
# --description--
When JavaScript variables are declared, they have an initial value of `undefined`. If you do a mathematical operation on an `undefined` variable your result will be `NaN` which means <dfn>"Not a Number"</dfn>. If you concatenate a string with an `undefined` variable, you will get a literal <dfn>string</dfn> of `"undefined"`.
When JavaScript variables are declared, they have an initial value of `undefined`. If you do a mathematical operation on an `undefined` variable your result will be `NaN` which means <dfn>"Not a Number"</dfn>. If you concatenate a string with an `undefined` variable, you will get a literal <dfn>string</dfn> of `undefined`.
# --instructions--
@ -29,7 +29,7 @@ assert(typeof a === 'number' && a === 6);
assert(typeof b === 'number' && b === 15);
```
`c` should not contain `undefined` and should have a value of "I am a String!"
`c` should not contain `undefined` and should have a value of the string `I am a String!`
```js
assert(!/undefined/.test(c) && c === 'I am a String!');

View File

@ -22,15 +22,15 @@ var ourDog = {
};
```
Since he's a particularly happy dog, let's change his name to "Happy Camper". Here's how we update his object's name property: `ourDog.name = "Happy Camper";` or `ourDog["name"] = "Happy Camper";` Now when we evaluate `ourDog.name`, instead of getting "Camper", we'll get his new name, "Happy Camper".
Since he's a particularly happy dog, let's change his name to the string `Happy Camper`. Here's how we update his object's name property: `ourDog.name = "Happy Camper";` or `ourDog["name"] = "Happy Camper";` Now when we evaluate `ourDog.name`, instead of getting `Camper`, we'll get his new name, `Happy Camper`.
# --instructions--
Update the `myDog` object's name property. Let's change her name from "Coder" to "Happy Coder". You can use either dot or bracket notation.
Update the `myDog` object's name property. Let's change her name from `Coder` to `Happy Coder`. You can use either dot or bracket notation.
# --hints--
You should update `myDog`'s `"name"` property to equal "Happy Coder".
You should update `myDog`'s `name` property to equal the string `Happy Coder`.
```js
assert(/happy coder/gi.test(myDog.name));

View File

@ -9,19 +9,21 @@ dashedName: use-bracket-notation-to-find-the-first-character-in-a-string
# --description--
<dfn>Bracket notation</dfn> is a way to get a character at a specific `index` within a string.
<dfn>Bracket notation</dfn> is a way to get a character at a specific index within a string.
Most modern programming languages, like JavaScript, don't start counting at 1 like humans do. They start at 0. This is referred to as <dfn>Zero-based</dfn> indexing.
For example, the character at index 0 in the word "Charles" is "C". So if `var firstName = "Charles"`, you can get the value of the first letter of the string by using `firstName[0]`.
For example, the character at index 0 in the word `Charles` is `C`. So if `var firstName = "Charles"`, you can get the value of the first letter of the string by using `firstName[0]`.
Example:
```js
var firstName = "Charles";
var firstLetter = firstName[0]; // firstLetter is "C"
var firstLetter = firstName[0];
```
`firstLetter` would have a value of the string `C`.
# --instructions--
Use bracket notation to find the first character in the `lastName` variable and assign it to `firstLetterOfLastName`.

View File

@ -17,9 +17,11 @@ Example:
```js
var firstName = "Charles";
var lastLetter = firstName[firstName.length - 1]; // lastLetter is "s"
var lastLetter = firstName[firstName.length - 1];
```
`lastLetter` would have a value of the string `s`.
# --instructions--
Use <dfn>bracket notation</dfn> to find the last character in the `lastName` variable.
@ -28,7 +30,7 @@ Use <dfn>bracket notation</dfn> to find the last character in the `lastName` var
# --hints--
`lastLetterOfLastName` should be "e".
`lastLetterOfLastName` should be the letter `e`.
```js
assert(lastLetterOfLastName === 'e');

View File

@ -17,9 +17,11 @@ Example:
```js
var firstName = "Ada";
var secondLetterOfFirstName = firstName[1]; // secondLetterOfFirstName is "d"
var secondLetterOfFirstName = firstName[1];
```
`secondLetterOfFirstName` would have a value of the string `d`.
# --instructions--
Let's try to set `thirdLetterOfLastName` to equal the third letter of the `lastName` variable using bracket notation.

View File

@ -17,9 +17,11 @@ Example:
```js
var firstName = "Charles";
var thirdToLastLetter = firstName[firstName.length - 3]; // thirdToLastLetter is "l"
var thirdToLastLetter = firstName[firstName.length - 3];
```
`thirdToLastLetter` would have a value of the string `l`.
# --instructions--
Use <dfn>bracket notation</dfn> to find the second-to-last character in the `lastName` string.
@ -28,7 +30,7 @@ Use <dfn>bracket notation</dfn> to find the second-to-last character in the `las
# --hints--
`secondToLastLetterOfLastName` should be "c".
`secondToLastLetterOfLastName` should be the letter `c`.
```js
assert(secondToLastLetterOfLastName === 'c');

View File

@ -26,15 +26,17 @@ function test (myCondition) {
}
return "It was false";
}
test(true); // returns "It was true"
test(false); // returns "It was false"
test(true);
test(false);
```
When `test` is called with a value of `true`, the `if` statement evaluates `myCondition` to see if it is `true` or not. Since it is `true`, the function returns `"It was true"`. When we call `test` with a value of `false`, `myCondition` is *not* `true` and the statement in the curly braces is not executed and the function returns `"It was false"`.
`test(true)` returns the string `It was true`, and `test(false)` returns the string `It was false`.
When `test` is called with a value of `true`, the `if` statement evaluates `myCondition` to see if it is `true` or not. Since it is `true`, the function returns `It was true`. When we call `test` with a value of `false`, `myCondition` is *not* `true` and the statement in the curly braces is not executed and the function returns `It was false`.
# --instructions--
Create an `if` statement inside the function to return `"Yes, that was true"` if the parameter `wasThatTrue` is `true` and return `"No, that was false"` otherwise.
Create an `if` statement inside the function to return `Yes, that was true` if the parameter `wasThatTrue` is `true` and return `No, that was false` otherwise.
# --hints--
@ -56,13 +58,13 @@ assert(typeof trueOrFalse(true) === 'string');
assert(typeof trueOrFalse(false) === 'string');
```
`trueOrFalse(true)` should return "Yes, that was true"
`trueOrFalse(true)` should return the string `Yes, that was true`
```js
assert(trueOrFalse(true) === 'Yes, that was true');
```
`trueOrFalse(false)` should return "No, that was false"
`trueOrFalse(false)` should return the string `No, that was false`
```js
assert(trueOrFalse(false) === 'No, that was false');

View File

@ -11,7 +11,7 @@ dashedName: use-multiple-conditional-ternary-operators
In the previous challenge, you used a single conditional operator. You can also chain them together to check for multiple conditions.
The following function uses if, else if, and else statements to check multiple conditions:
The following function uses `if`, `else if`, and `else` statements to check multiple conditions:
```js
function findGreaterOrEqual(a, b) {
@ -47,7 +47,7 @@ function findGreaterOrEqual(a, b) {
# --instructions--
In the `checkSign` function, use multiple conditional operators - following the recommended format used in `findGreaterOrEqual` - to check if a number is positive, negative or zero. The function should return `"positive"`, `"negative"` or `"zero"`.
In the `checkSign` function, use multiple conditional operators - following the recommended format used in `findGreaterOrEqual` - to check if a number is positive, negative or zero. The function should return `positive`, `negative` or `zero`.
# --hints--
@ -57,19 +57,19 @@ In the `checkSign` function, use multiple conditional operators - following the
assert(/.+?\s*?\?\s*?.+?\s*?:\s*?.+?\s*?\?\s*?.+?\s*?:\s*?.+?/gi.test(code));
```
`checkSign(10)` should return "positive". Note that capitalization matters
`checkSign(10)` should return the string `positive`. Note that capitalization matters
```js
assert(checkSign(10) === 'positive');
```
`checkSign(-12)` should return "negative". Note that capitalization matters
`checkSign(-12)` should return the string `negative`. Note that capitalization matters
```js
assert(checkSign(-12) === 'negative');
```
`checkSign(0)` should return "zero". Note that capitalization matters
`checkSign(0)` should return the string `zero`. Note that capitalization matters
```js
assert(checkSign(0) === 'zero');

View File

@ -8,7 +8,7 @@ dashedName: use-recursion-to-create-a-countdown
# --description--
In a [previous challenge](/learn/javascript-algorithms-and-data-structures/basic-javascript/replace-loops-using-recursion), you learned how to use recursion to replace a for loop. Now, let's look at a more complex function that returns an array of consecutive integers starting with `1` through the number passed to the function.
In a [previous challenge](/learn/javascript-algorithms-and-data-structures/basic-javascript/replace-loops-using-recursion), you learned how to use recursion to replace a `for` loop. Now, let's look at a more complex function that returns an array of consecutive integers starting with `1` through the number passed to the function.
As mentioned in the previous challenge, there will be a <dfn>base case</dfn>. The base case tells the recursive function when it no longer needs to call itself. It is a simple case where the return value is already known. There will also be a <dfn>recursive call</dfn> which executes the original function with different arguments. If the function is written correctly, eventually the base case will be reached.
@ -24,9 +24,11 @@ function countup(n) {
return countArray;
}
}
console.log(countup(5)); // [ 1, 2, 3, 4, 5 ]
console.log(countup(5));
```
The value `[1, 2, 3, 4, 5]` will be displayed in the console.
At first, this seems counterintuitive since the value of `n` *decreases*, but the values in the final array are *increasing*. This happens because the push happens last, after the recursive call has returned. At the point where `n` is pushed into the array, `countup(n - 1)` has already been evaluated and returned `[1, 2, ..., n - 1]`.
# --instructions--

View File

@ -10,11 +10,9 @@ dashedName: use-the-conditional-ternary-operator
The <dfn>conditional operator</dfn>, also called the <dfn>ternary operator</dfn>, can be used as a one line if-else expression.
The syntax is:
The syntax is `a ? b : c`, where `a` is the condition, `b` is the code to run when the condition returns `true`, and `c` is the code to run when the condition returns `false`.
`condition ? expression-if-true : expression-if-false;`
The following function uses an if-else statement to check a condition:
The following function uses an `if/else` statement to check a condition:
```js
function findGreater(a, b) {
@ -27,7 +25,7 @@ function findGreater(a, b) {
}
```
This can be re-written using the `conditional operator`:
This can be re-written using the conditional operator:
```js
function findGreater(a, b) {
@ -37,7 +35,7 @@ function findGreater(a, b) {
# --instructions--
Use the `conditional operator` in the `checkEqual` function to check if two numbers are equal or not. The function should return either "Equal" or "Not Equal".
Use the conditional operator in the `checkEqual` function to check if two numbers are equal or not. The function should return either the string `Equal` or the string `Not Equal`.
# --hints--
@ -47,19 +45,19 @@ Use the `conditional operator` in the `checkEqual` function to check if two numb
assert(/.+?\s*?\?\s*?.+?\s*?:\s*?.+?/.test(code));
```
`checkEqual(1, 2)` should return "Not Equal"
`checkEqual(1, 2)` should return the string `Not Equal`
```js
assert(checkEqual(1, 2) === 'Not Equal');
```
`checkEqual(1, 1)` should return "Equal"
`checkEqual(1, 1)` should return the string `Equal`
```js
assert(checkEqual(1, 1) === 'Equal');
```
`checkEqual(1, -1)` should return "Not Equal"
`checkEqual(1, -1)` should return the string `Not Equal`
```js
assert(checkEqual(1, -1) === 'Not Equal');

View File

@ -19,7 +19,7 @@ And here's an example:
`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.
The radix variable says that `11` is in the binary system, or base 2. This example converts the string `11` to an integer `3`.
# --instructions--
@ -51,7 +51,7 @@ assert(convertToInteger('10011') === 19);
assert(convertToInteger('111001') === 57);
```
`convertToInteger("JamesBond")` should return NaN
`convertToInteger("JamesBond")` should return `NaN`
```js
assert.isNaN(convertToInteger('JamesBond'));

View File

@ -13,7 +13,7 @@ The `parseInt()` function parses a string and returns an integer. Here's an exam
`var a = parseInt("007");`
The above function converts the string "007" to an integer 7. If the first character in the string can't be converted into a number, then it returns `NaN`.
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`.
# --instructions--
@ -45,7 +45,7 @@ assert(convertToInteger('56') === 56);
assert(convertToInteger('77') === 77);
```
`convertToInteger("JamesBond")` should return NaN
`convertToInteger("JamesBond")` should return `NaN`
```js
assert.isNaN(convertToInteger('JamesBond'));

View File

@ -9,7 +9,7 @@ dashedName: using-objects-for-lookups
# --description--
Objects can be thought of as a key/value storage, like a dictionary. If you have tabular data, you can use an object to "lookup" values rather than a `switch` statement or an `if/else` chain. This is most useful when you know that your input data is limited to a certain range.
Objects can be thought of as a key/value storage, like a dictionary. If you have tabular data, you can use an object to lookup values rather than a `switch` statement or an `if/else` chain. This is most useful when you know that your input data is limited to a certain range.
Here is an example of a simple reverse alphabet lookup:
@ -24,50 +24,52 @@ var alpha = {
25:"B",
26:"A"
};
alpha[2]; // "Y"
alpha[24]; // "C"
alpha[2];
alpha[24];
var value = 2;
alpha[value]; // "Y"
alpha[value];
```
`alpha[2]` is the string `Y`, `alpha[24]` is the string `C`, and `alpha[value]` is the string `Y`.
# --instructions--
Convert the switch statement into an object called `lookup`. Use it to look up `val` and assign the associated string to the `result` variable.
# --hints--
`phoneticLookup("alpha")` should equal `"Adams"`
`phoneticLookup("alpha")` should equal the string `Adams`
```js
assert(phoneticLookup('alpha') === 'Adams');
```
`phoneticLookup("bravo")` should equal `"Boston"`
`phoneticLookup("bravo")` should equal the string `Boston`
```js
assert(phoneticLookup('bravo') === 'Boston');
```
`phoneticLookup("charlie")` should equal `"Chicago"`
`phoneticLookup("charlie")` should equal the string `Chicago`
```js
assert(phoneticLookup('charlie') === 'Chicago');
```
`phoneticLookup("delta")` should equal `"Denver"`
`phoneticLookup("delta")` should equal the string `Denver`
```js
assert(phoneticLookup('delta') === 'Denver');
```
`phoneticLookup("echo")` should equal `"Easy"`
`phoneticLookup("echo")` should equal the string `Easy`
```js
assert(phoneticLookup('echo') === 'Easy');
```
`phoneticLookup("foxtrot")` should equal `"Frank"`
`phoneticLookup("foxtrot")` should equal the string `Frank`
```js
assert(phoneticLookup('foxtrot') === 'Frank');

View File

@ -13,7 +13,7 @@ We will now use our knowledge of strings to build a "[Mad Libs](https://en.wikip
In a "Mad Libs" game, you are provided sentences with some missing words, like nouns, verbs, adjectives and adverbs. You then fill in the missing pieces with words of your choice in a way that the completed sentence makes sense.
Consider this sentence - "It was really **\_\_\_\_**, and we **\_\_\_\_** ourselves **\_\_\_\_**". This sentence has three missing pieces- an adjective, a verb and an adverb, and we can add words of our choice to complete it. We can then assign the completed sentence to a variable as follows:
Consider this sentence - It was really **\_\_\_\_**, and we **\_\_\_\_** ourselves **\_\_\_\_**. This sentence has three missing pieces- an adjective, a verb and an adverb, and we can add words of our choice to complete it. We can then assign the completed sentence to a variable as follows:
```js
var sentence = "It was really " + "hot" + ", and we " + "laughed" + " ourselves " + "silly" + ".";
@ -46,7 +46,7 @@ assert(
);
```
You should not directly use the values "dog", "ran", "big", or "quickly" to create `wordBlanks`.
You should not directly use the values `dog`, `ran`, `big`, or `quickly` to create `wordBlanks`.
```js
const newCode = removeAssignments(code);

View File

@ -19,7 +19,7 @@ function functionName() {
}
```
You can call or <dfn>invoke</dfn> this function by using its name followed by parentheses, like this: `functionName();` Each time the function is called it will print out the message `"Hello World"` on the dev console. All of the code between the curly braces will be executed every time the function is called.
You can call or <dfn>invoke</dfn> this function by using its name followed by parentheses, like this: `functionName();` Each time the function is called it will print out the message `Hello World` on the dev console. All of the code between the curly braces will be executed every time the function is called.
# --instructions--
@ -33,7 +33,7 @@ You can call or <dfn>invoke</dfn> this function by using its name followed by pa
assert(typeof reusableFunction === 'function');
```
`reusableFunction` should output "Hi World" to the dev console.
`reusableFunction` should output the string `Hi World` to the console.
```js
assert(hiWorldWasLogged);