fix(curriculum): Consolidated comments for JavaScript Algorithms and Data Structures challenges - part 3 of 4 (#38264)
* fix: remove example code from challenge seed * fix: remove declaration from solution * fix: added sum variable back in * fix: reverted description back to original version * fix: added examples to description section * fix: added complete sentence Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: corrected typo Co-Authored-By: Manish Giri <manish.giri.me@gmail.com> * fix: reverted to original desc with formatted code * fix: removed unnecessary code example from description section Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: failiing test on iterate through array with for loop * fix: changed to Only change this line Co-Authored-By: Manish Giri <manish.giri.me@gmail.com> Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> Co-authored-by: Manish Giri <manish.giri.me@gmail.com> Co-authored-by: moT01 <tmondloch01@gmail.com>
This commit is contained in:
@ -47,10 +47,6 @@ tests:
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// Example
|
||||
var ourArray = [50,60,70];
|
||||
var ourData = ourArray[0]; // equals 50
|
||||
|
||||
// Setup
|
||||
var myArray = [50,60,70];
|
||||
|
||||
|
@ -14,6 +14,20 @@ Here's how we would add a <code>"bark"</code> property to <code>ourDog</code>:
|
||||
or
|
||||
<code>ourDog["bark"] = "bow-wow";</code>
|
||||
Now when we evaluate <code>ourDog.bark</code>, we'll get his bark, "bow-wow".
|
||||
|
||||
Example:
|
||||
|
||||
```js
|
||||
var ourDog = {
|
||||
"name": "Camper",
|
||||
"legs": 4,
|
||||
"tails": 1,
|
||||
"friends": ["everything!"]
|
||||
};
|
||||
|
||||
ourDog.bark = "bow-wow";
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Instructions
|
||||
@ -41,16 +55,6 @@ tests:
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// Example
|
||||
var ourDog = {
|
||||
"name": "Camper",
|
||||
"legs": 4,
|
||||
"tails": 1,
|
||||
"friends": ["everything!"]
|
||||
};
|
||||
|
||||
ourDog.bark = "bow-wow";
|
||||
|
||||
// Setup
|
||||
var myDog = {
|
||||
"name": "Happy Coder",
|
||||
|
@ -9,6 +9,16 @@ forumTopicId: 16656
|
||||
## Description
|
||||
<section id='description'>
|
||||
Just as we can build a string over multiple lines out of string <dfn>literals</dfn>, we can also append variables to a string using the plus equals (<code>+=</code>) operator.
|
||||
|
||||
Example:
|
||||
|
||||
```js
|
||||
var anAdjective = "awesome!";
|
||||
var ourStr = "freeCodeCamp is ";
|
||||
ourStr += anAdjective;
|
||||
// ourStr is now "freeCodeCamp is awesome!"
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Instructions
|
||||
@ -36,12 +46,7 @@ tests:
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// Example
|
||||
var anAdjective = "awesome!";
|
||||
var ourStr = "freeCodeCamp is ";
|
||||
ourStr += anAdjective;
|
||||
|
||||
// Only change code below this line
|
||||
// Change code below this line
|
||||
|
||||
var someAdjective;
|
||||
var myStr = "Learning to code is ";
|
||||
|
@ -39,15 +39,6 @@ tests:
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// Example
|
||||
var changed = 0;
|
||||
|
||||
function change(num) {
|
||||
return (num + 5) / 3;
|
||||
}
|
||||
|
||||
changed = change(10);
|
||||
|
||||
// Setup
|
||||
var processed = 0;
|
||||
|
||||
@ -57,7 +48,6 @@ function processArg(num) {
|
||||
|
||||
// Only change code below this line
|
||||
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
@ -68,10 +68,10 @@ tests:
|
||||
|
||||
```js
|
||||
var myDog = {
|
||||
// Only change code below this line
|
||||
|
||||
|
||||
|
||||
|
||||
// Only change code above this line
|
||||
};
|
||||
```
|
||||
|
||||
|
@ -16,6 +16,14 @@ In JavaScript, when the <code>+</code> operator is used with a <code>String</cod
|
||||
```
|
||||
|
||||
<strong>Note</strong><br>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."
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Instructions
|
||||
@ -47,13 +55,7 @@ tests:
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// Example
|
||||
var ourStr = "I come first. " + "I come second.";
|
||||
|
||||
// Only change code below this line
|
||||
|
||||
var myStr;
|
||||
|
||||
var myStr; // Only change this line
|
||||
|
||||
```
|
||||
|
||||
|
@ -10,6 +10,15 @@ forumTopicId: 16803
|
||||
<section id='description'>
|
||||
We can also use the <code>+=</code> 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.
|
||||
<strong>Note</strong><br>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."
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Instructions
|
||||
@ -37,9 +46,6 @@ tests:
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// Example
|
||||
var ourStr = "I come first. ";
|
||||
ourStr += "I come second.";
|
||||
|
||||
// Only change code below this line
|
||||
|
||||
|
@ -9,6 +9,15 @@ forumTopicId: 16805
|
||||
## Description
|
||||
<section id='description'>
|
||||
Sometimes you will need to build a string, <a href="https://en.wikipedia.org/wiki/Mad_Libs" target="_blank">Mad Libs</a> style. By using the concatenation operator (<code>+</code>), you can insert one or more variables into a string you're building.
|
||||
|
||||
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?"
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Instructions
|
||||
@ -36,10 +45,6 @@ tests:
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// Example
|
||||
var ourName = "freeCodeCamp";
|
||||
var ourStr = "Hello, our name is " + ourName + ", how are you?";
|
||||
|
||||
// Only change code below this line
|
||||
var myName;
|
||||
var myStr;
|
||||
|
@ -14,7 +14,7 @@ We'll start at <code>i = 10</code> and loop while <code>i > 0</code>. We'll
|
||||
|
||||
```js
|
||||
var ourArray = [];
|
||||
for (var i=10; i > 0; i-=2) {
|
||||
for (var i = 10; i > 0; i -= 2) {
|
||||
ourArray.push(i);
|
||||
}
|
||||
```
|
||||
@ -50,13 +50,6 @@ tests:
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// Example
|
||||
var ourArray = [];
|
||||
|
||||
for (var i = 10; i > 0; i -= 2) {
|
||||
ourArray.push(i);
|
||||
}
|
||||
|
||||
// Setup
|
||||
var myArray = [];
|
||||
|
||||
|
@ -38,11 +38,7 @@ tests:
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// Example
|
||||
var firstName = "Alan";
|
||||
var lastName = "Turing";
|
||||
|
||||
// Only change code below this line
|
||||
|
||||
|
||||
```
|
||||
|
@ -10,6 +10,33 @@ forumTopicId: 17560
|
||||
<section id='description'>
|
||||
We can also delete properties from objects like this:
|
||||
<code>delete ourDog.bark;</code>
|
||||
|
||||
Example:
|
||||
|
||||
```js
|
||||
var ourDog = {
|
||||
"name": "Camper",
|
||||
"legs": 4,
|
||||
"tails": 1,
|
||||
"friends": ["everything!"],
|
||||
"bark": "bow-wow"
|
||||
};
|
||||
|
||||
delete ourDog.bark;
|
||||
```
|
||||
|
||||
After the last line shown above, <code>ourDog</code> looks like:
|
||||
|
||||
```js
|
||||
{
|
||||
"name": "Camper",
|
||||
"legs": 4,
|
||||
"tails": 1,
|
||||
"friends": ["everything!"]
|
||||
}
|
||||
*/
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Instructions
|
||||
@ -37,17 +64,6 @@ tests:
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// Example
|
||||
var ourDog = {
|
||||
"name": "Camper",
|
||||
"legs": 4,
|
||||
"tails": 1,
|
||||
"friends": ["everything!"],
|
||||
"bark": "bow-wow"
|
||||
};
|
||||
|
||||
delete ourDog.bark;
|
||||
|
||||
// Setup
|
||||
var myDog = {
|
||||
"name": "Happy Coder",
|
||||
|
@ -40,12 +40,6 @@ tests:
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// Example
|
||||
var firstNameLength = 0;
|
||||
var firstName = "Ada";
|
||||
|
||||
firstNameLength = firstName.length;
|
||||
|
||||
// Setup
|
||||
var lastNameLength = 0;
|
||||
var lastName = "Lovelace";
|
||||
|
@ -43,23 +43,11 @@ tests:
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// Example
|
||||
function ourRandomRange(ourMin, ourMax) {
|
||||
|
||||
return Math.floor(Math.random() * (ourMax - ourMin + 1)) + ourMin;
|
||||
}
|
||||
|
||||
ourRandomRange(1, 9);
|
||||
|
||||
// Only change code below this line
|
||||
|
||||
function randomRange(myMin, myMax) {
|
||||
|
||||
return 0; // Change this line
|
||||
|
||||
// Only change code below this line
|
||||
return 0;
|
||||
// Only change code above this line
|
||||
}
|
||||
|
||||
var myRandom = randomRange(5, 15);
|
||||
```
|
||||
|
||||
</div>
|
||||
|
@ -36,10 +36,7 @@ tests:
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// Example
|
||||
var ourVar = 19;
|
||||
|
||||
// Only change code below this line
|
||||
|
||||
```
|
||||
|
||||
|
@ -47,13 +47,6 @@ tests:
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// Example
|
||||
var ourArray = [];
|
||||
|
||||
for (var i = 0; i < 10; i += 2) {
|
||||
ourArray.push(i);
|
||||
}
|
||||
|
||||
// Setup
|
||||
var myArray = [];
|
||||
|
||||
|
@ -35,7 +35,7 @@ tests:
|
||||
- text: <code>total</code> should equal 20.
|
||||
testString: assert(total === 20);
|
||||
- text: You should use a <code>for</code> loop to iterate through <code>myArr</code>.
|
||||
testString: assert(code.match(/for\s*\(/g).length > 1 && code.match(/myArr\s*\[/));
|
||||
testString: assert(/for\s*\(/g.test(code) && /myArr\s*\[/g.test(code));
|
||||
- text: You should not attempt to directly assign the value 20 to <code>total</code>.
|
||||
testString: assert(!code.replace(/\s/g, '').match(/total[=+-]0*[1-9]+/gm));
|
||||
```
|
||||
@ -47,14 +47,6 @@ tests:
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// Example
|
||||
var ourArr = [ 9, 10, 11, 12];
|
||||
var ourTotal = 0;
|
||||
|
||||
for (var i = 0; i < ourArr.length; i++) {
|
||||
ourTotal += ourArr[i];
|
||||
}
|
||||
|
||||
// Setup
|
||||
var myArr = [ 2, 3, 4, 5, 6];
|
||||
|
||||
@ -80,13 +72,6 @@ var myArr = [ 2, 3, 4, 5, 6];
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
var ourArr = [ 9, 10, 11, 12];
|
||||
var ourTotal = 0;
|
||||
|
||||
for (var i = 0; i < ourArr.length; i++) {
|
||||
ourTotal += ourArr[i];
|
||||
}
|
||||
|
||||
var myArr = [ 2, 3, 4, 5, 6];
|
||||
var total = 0;
|
||||
|
||||
|
@ -52,13 +52,6 @@ tests:
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// Example
|
||||
var ourArray = [];
|
||||
|
||||
for (var i = 0; i < 5; i++) {
|
||||
ourArray.push(i);
|
||||
}
|
||||
|
||||
// Setup
|
||||
var myArray = [];
|
||||
|
||||
|
@ -48,11 +48,6 @@ tests:
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// Example
|
||||
var ourArray = [1,2,3];
|
||||
var removedFromOurArray = ourArray.pop();
|
||||
// removedFromOurArray now equals 3, and ourArray now equals [1,2]
|
||||
|
||||
// Setup
|
||||
var myArray = [["John", 23], ["cat", 2]];
|
||||
|
||||
|
@ -11,10 +11,16 @@ forumTopicId: 18237
|
||||
An easy way to append data to the end of an array is via the <code>push()</code> function.
|
||||
<code>.push()</code> takes one or more <dfn>parameters</dfn> and "pushes" them onto the end of the array.
|
||||
|
||||
Examples:
|
||||
|
||||
```js
|
||||
var arr = [1,2,3];
|
||||
arr.push(4);
|
||||
// arr is now [1,2,3,4]
|
||||
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"]]
|
||||
```
|
||||
|
||||
</section>
|
||||
@ -42,11 +48,6 @@ tests:
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// Example
|
||||
var ourArray = ["Stimpson", "J", "cat"];
|
||||
ourArray.push(["happy", "joy"]);
|
||||
// ourArray now equals ["Stimpson", "J", "cat", ["happy", "joy"]]
|
||||
|
||||
// Setup
|
||||
var myArray = [["John", 23], ["cat", 2]];
|
||||
|
||||
|
@ -10,6 +10,15 @@ forumTopicId: 18238
|
||||
<section id='description'>
|
||||
<code>pop()</code> always removes the last element of an array. What if you want to remove the first?
|
||||
That's where <code>.shift()</code> comes in. It works just like <code>.pop()</code>, except it removes the first element instead of the last.
|
||||
|
||||
Example:
|
||||
|
||||
```js
|
||||
var ourArray = ["Stimpson", "J", ["cat"]];
|
||||
var removedFromOurArray = ourArray.shift();
|
||||
// removedFromOurArray now equals "Stimpson" and ourArray now equals ["J", ["cat"]].
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Instructions
|
||||
@ -37,11 +46,6 @@ tests:
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// Example
|
||||
var ourArray = ["Stimpson", "J", ["cat"]];
|
||||
var removedFromOurArray = ourArray.shift();
|
||||
// removedFromOurArray now equals "Stimpson" and ourArray now equals ["J", ["cat"]].
|
||||
|
||||
// Setup
|
||||
var myArray = [["John", 23], ["dog", 3]];
|
||||
|
||||
|
@ -10,6 +10,16 @@ forumTopicId: 18239
|
||||
<section id='description'>
|
||||
Not only can you <code>shift</code> elements off of the beginning of an array, you can also <code>unshift</code> elements to the beginning of an array i.e. add elements in front of the array.
|
||||
<code>.unshift()</code> works exactly like <code>.push()</code>, but instead of adding the element at the end of the array, <code>unshift()</code> adds the element at the beginning of the array.
|
||||
|
||||
Example:
|
||||
|
||||
```js
|
||||
var ourArray = ["Stimpson", "J", "cat"];
|
||||
ourArray.shift(); // ourArray now equals ["J", "cat"]
|
||||
ourArray.unshift("Happy");
|
||||
// ourArray now equals ["Happy", "J", "cat"]
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Instructions
|
||||
@ -35,12 +45,6 @@ tests:
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// Example
|
||||
var ourArray = ["Stimpson", "J", "cat"];
|
||||
ourArray.shift(); // ourArray now equals ["J", "cat"]
|
||||
ourArray.unshift("Happy");
|
||||
// ourArray now equals ["Happy", "J", "cat"]
|
||||
|
||||
// Setup
|
||||
var myArray = [["John", 23], ["dog", 3]];
|
||||
myArray.shift();
|
||||
|
@ -44,10 +44,6 @@ tests:
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// Example
|
||||
var ourArray = [18,64,99];
|
||||
ourArray[1] = 45; // ourArray now equals [18,45,99].
|
||||
|
||||
// Setup
|
||||
var myArray = [18,64,99];
|
||||
|
||||
|
@ -8,7 +8,13 @@ forumTopicId: 18247
|
||||
|
||||
## Description
|
||||
<section id='description'>
|
||||
You can also nest arrays within other arrays, like this: <code>[["Bulls", 23], ["White Sox", 45]]</code>. This is also called a <dfn>multi-dimensional array<dfn>.
|
||||
You can also nest arrays within other arrays, like below:
|
||||
|
||||
```js
|
||||
[["Bulls", 23], ["White Sox", 45]]
|
||||
```
|
||||
|
||||
This is also called a <dfn>multi-dimensional array<dfn>.
|
||||
</section>
|
||||
|
||||
## Instructions
|
||||
@ -34,9 +40,6 @@ tests:
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// Example
|
||||
var ourArray = [["the universe", 42], ["everything", 101010]];
|
||||
|
||||
// Only change code below this line
|
||||
var myArray = [];
|
||||
|
||||
|
@ -51,13 +51,7 @@ tests:
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// Example
|
||||
function ourFunctionWithArgs(a, b) {
|
||||
console.log(a - b);
|
||||
}
|
||||
ourFunctionWithArgs(10, 5); // Outputs 5
|
||||
|
||||
// Only change code below this line
|
||||
|
||||
|
||||
```
|
||||
|
@ -50,16 +50,9 @@ tests:
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// Example
|
||||
function minusSeven(num) {
|
||||
return num - 7;
|
||||
}
|
||||
|
||||
// Only change code below this line
|
||||
|
||||
|
||||
|
||||
console.log(minusSeven(10));
|
||||
```
|
||||
|
||||
</div>
|
||||
|
@ -41,9 +41,6 @@ tests:
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// Example
|
||||
var ourArray = ["John", 23];
|
||||
|
||||
// Only change code below this line
|
||||
var myArray = [];
|
||||
|
||||
|
@ -51,15 +51,18 @@ tests:
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// Example
|
||||
// Setup
|
||||
var sum = 0;
|
||||
|
||||
function addThree() {
|
||||
sum = sum + 3;
|
||||
}
|
||||
|
||||
// Only change code below this line
|
||||
|
||||
|
||||
// Only change code above this line
|
||||
|
||||
addThree();
|
||||
addFive();
|
||||
```
|
||||
@ -72,19 +75,16 @@ addFive();
|
||||
|
||||
|
||||
```js
|
||||
// Example
|
||||
var sum = 0;
|
||||
|
||||
function addThree() {
|
||||
sum = sum + 3;
|
||||
}
|
||||
|
||||
// Only change code below this line
|
||||
|
||||
function addFive() {
|
||||
sum = sum + 5;
|
||||
}
|
||||
|
||||
// Only change code above this line
|
||||
addThree();
|
||||
addFive();
|
||||
```
|
||||
|
@ -51,16 +51,6 @@ tests:
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// Example
|
||||
var ourDog = {
|
||||
"name": "Camper",
|
||||
"legs": 4,
|
||||
"tails": 1,
|
||||
"friends": ["everything!"]
|
||||
};
|
||||
|
||||
ourDog.name = "Happy Camper";
|
||||
|
||||
// Setup
|
||||
var myDog = {
|
||||
"name": "Coder",
|
||||
|
@ -11,12 +11,20 @@ forumTopicId: 18341
|
||||
<dfn>Bracket notation</dfn> is a way to get a character at a specific <code>index</code> 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 <code>var firstName = "Charles"</code>, you can get the value of the first letter of the string by using <code>firstName[0]</code>.
|
||||
|
||||
Example:
|
||||
|
||||
```js
|
||||
var firstName = "Charles";
|
||||
var firstLetter = firstName[0]; // firstLetter is "C"
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Instructions
|
||||
<section id='instructions'>
|
||||
Use bracket notation to find the first character in the <code>lastName</code> variable and assign it to <code>firstLetterOfLastName</code>.
|
||||
<strong>Hint</strong><br>Try looking at the <code>firstLetterOfFirstName</code> variable declaration if you get stuck.
|
||||
<strong>Hint: </strong> Try looking at the example above if you get stuck.
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
@ -39,19 +47,12 @@ tests:
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// Example
|
||||
var firstLetterOfFirstName = "";
|
||||
var firstName = "Ada";
|
||||
|
||||
firstLetterOfFirstName = firstName[0];
|
||||
|
||||
// Setup
|
||||
var firstLetterOfLastName = "";
|
||||
var lastName = "Lovelace";
|
||||
|
||||
// Only change code below this line
|
||||
firstLetterOfLastName = lastName;
|
||||
|
||||
firstLetterOfLastName = lastName; // Change this line
|
||||
|
||||
```
|
||||
|
||||
|
@ -10,12 +10,20 @@ forumTopicId: 18342
|
||||
<section id='description'>
|
||||
In order to get the last letter of a string, you can subtract one from the string's length.
|
||||
For example, if <code>var firstName = "Charles"</code>, you can get the value of the last letter of the string by using <code>firstName[firstName.length - 1]</code>.
|
||||
|
||||
Example:
|
||||
|
||||
```js
|
||||
var firstName = "Charles";
|
||||
var lastLetter = firstName[firstName.length - 1]; // lastLetter is "s"
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Instructions
|
||||
<section id='instructions'>
|
||||
Use <dfn>bracket notation</dfn> to find the last character in the <code>lastName</code> variable.
|
||||
<strong>Hint</strong><br>Try looking at the <code>lastLetterOfFirstName</code> variable declaration if you get stuck.
|
||||
<strong>Hint: </strong> Try looking at the example above if you get stuck.
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
@ -26,7 +34,7 @@ tests:
|
||||
- text: <code>lastLetterOfLastName</code> should be "e".
|
||||
testString: assert(lastLetterOfLastName === "e");
|
||||
- text: You should use <code>.length</code> to get the last letter.
|
||||
testString: assert(code.match(/\.length/g).length === 2);
|
||||
testString: assert(code.match(/\.length/g).length > 0);
|
||||
|
||||
```
|
||||
|
||||
@ -38,15 +46,11 @@ tests:
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// Example
|
||||
var firstName = "Ada";
|
||||
var lastLetterOfFirstName = firstName[firstName.length - 1];
|
||||
|
||||
// Setup
|
||||
var lastName = "Lovelace";
|
||||
|
||||
// Only change code below this line
|
||||
var lastLetterOfLastName = lastName;
|
||||
var lastLetterOfLastName = lastName; // Change this line
|
||||
|
||||
|
||||
```
|
||||
@ -70,9 +74,6 @@ var lastLetterOfLastName = lastName;
|
||||
|
||||
|
||||
```js
|
||||
var firstName = "Ada";
|
||||
var lastLetterOfFirstName = firstName[firstName.length - 1];
|
||||
|
||||
var lastName = "Lovelace";
|
||||
var lastLetterOfLastName = lastName[lastName.length - 1];
|
||||
```
|
||||
|
@ -10,12 +10,20 @@ forumTopicId: 18343
|
||||
<section id='description'>
|
||||
You can also use <dfn>bracket notation</dfn> to get the character at other positions within a string.
|
||||
Remember that computers start counting at <code>0</code>, so the first character is actually the zeroth character.
|
||||
|
||||
Example:
|
||||
|
||||
```js
|
||||
var firstName = "Ada";
|
||||
var secondLetterOfFirstName = firstName[1]; // secondLetterOfFirstName is "d"
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Instructions
|
||||
<section id='instructions'>
|
||||
Let's try to set <code>thirdLetterOfLastName</code> to equal the third letter of the <code>lastName</code> variable using bracket notation.
|
||||
<strong>Hint</strong><br>Try looking at the <code>secondLetterOfFirstName</code> variable declaration if you get stuck.
|
||||
<strong>Hint: </strong> Try looking at the example above if you get stuck.
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
@ -38,15 +46,11 @@ tests:
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// Example
|
||||
var firstName = "Ada";
|
||||
var secondLetterOfFirstName = firstName[1];
|
||||
|
||||
// Setup
|
||||
var lastName = "Lovelace";
|
||||
|
||||
// Only change code below this line
|
||||
var thirdLetterOfLastName = lastName;
|
||||
var thirdLetterOfLastName = lastName; // Change this line
|
||||
|
||||
|
||||
```
|
||||
|
@ -10,12 +10,20 @@ forumTopicId: 18344
|
||||
<section id='description'>
|
||||
You can use the same principle we just used to retrieve the last character in a string to retrieve the Nth-to-last character.
|
||||
For example, you can get the value of the third-to-last letter of the <code>var firstName = "Charles"</code> string by using <code>firstName[firstName.length - 3]</code>
|
||||
|
||||
Example:
|
||||
|
||||
```js
|
||||
var firstName = "Charles";
|
||||
var thirdToLastLetter = firstName[firstName.length - 3]; // thirdToLastLetter is "l"
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Instructions
|
||||
<section id='instructions'>
|
||||
Use <dfn>bracket notation</dfn> to find the second-to-last character in the <code>lastName</code> string.
|
||||
<strong>Hint</strong><br>Try looking at the <code>thirdToLastLetterOfFirstName</code> variable declaration if you get stuck.
|
||||
<strong>Hint: </strong> Try looking at the example above if you get stuck.
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
@ -26,7 +34,7 @@ tests:
|
||||
- text: <code>secondToLastLetterOfLastName</code> should be "c".
|
||||
testString: assert(secondToLastLetterOfLastName === 'c');
|
||||
- text: You should use <code>.length</code> to get the second last letter.
|
||||
testString: assert(code.match(/\.length/g).length === 2);
|
||||
testString: assert(code.match(/\.length/g).length > 0);
|
||||
|
||||
```
|
||||
|
||||
@ -38,15 +46,11 @@ tests:
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// Example
|
||||
var firstName = "Ada";
|
||||
var thirdToLastLetterOfFirstName = firstName[firstName.length - 3];
|
||||
|
||||
// Setup
|
||||
var lastName = "Lovelace";
|
||||
|
||||
// Only change code below this line
|
||||
var secondToLastLetterOfLastName = lastName;
|
||||
var secondToLastLetterOfLastName = lastName; // Change this line
|
||||
|
||||
|
||||
```
|
||||
|
@ -59,17 +59,7 @@ tests:
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// Example
|
||||
function ourTrueOrFalse(isItTrue) {
|
||||
if (isItTrue) {
|
||||
return "Yes, it's true";
|
||||
}
|
||||
return "No, it's false";
|
||||
}
|
||||
|
||||
// Setup
|
||||
function trueOrFalse(wasThatTrue) {
|
||||
|
||||
// Only change code below this line
|
||||
|
||||
|
||||
@ -77,8 +67,6 @@ function trueOrFalse(wasThatTrue) {
|
||||
// Only change code above this line
|
||||
|
||||
}
|
||||
|
||||
trueOrFalse(true);
|
||||
```
|
||||
|
||||
</div>
|
||||
|
@ -72,7 +72,6 @@ function countdown(n){
|
||||
return;
|
||||
}
|
||||
// Only change code above this line
|
||||
console.log(countdown(5)); // [5, 4, 3, 2, 1]
|
||||
```
|
||||
|
||||
</div>
|
||||
|
@ -49,14 +49,8 @@ tests:
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// Example
|
||||
function ourReusableFunction() {
|
||||
console.log("Heyya, World");
|
||||
}
|
||||
|
||||
ourReusableFunction();
|
||||
|
||||
// Only change code below this line
|
||||
|
||||
```
|
||||
|
||||
|
Reference in New Issue
Block a user