Show/Hide sections with changes/issues
- **`Description` section has changed**
```diff
@@ -1,5 +1,4 @@
Given a positive integer num, return the sum of all odd Fibonacci numbers that are less than or equal to num.
The first two numbers in the Fibonacci sequence are 1 and 1. Every additional number in the sequence is the sum of the two previous numbers. The first six numbers of the Fibonacci sequence are 1, 1, 2, 3, 5 and 8.
-
For example, sumFibs(10) should return 10 because all odd Fibonacci numbers less than or equal to 10 are 1, 1, 3, and 5.
-
Remember to use Read-Search-Ask if you get stuck. Try to pair program. Write your own code.
\ No newline at end of file
+
For example, sumFibs(10) should return 10 because all odd Fibonacci numbers less than or equal to 10 are 1, 1, 3, and 5.
Show/Hide sections with changes/issues
- **`Description` section has changed**
```diff
@@ -1,3 +1,2 @@
-
You will be provided with an initial array (the first argument in the destroyer function), followed by one or more arguments. Remove all elements from the initial array that are of the same value as these arguments.
Note You have to use the arguments object.
-
Remember to use Read-Search-Ask if you get stuck. Write your own code.
\ No newline at end of file
+
You will be provided with an initial array (the first argument in the destroyer function), followed by one or more arguments. Remove all elements from the initial array that are of the same value as these arguments.
Show/Hide sections with changes/issues
- **`Description` section has changed**
```diff
@@ -4,5 +4,4 @@ itself. For example, 2 is a prime number because it is only divisible by 1 and 2
contrast, 4 is not prime since it is divisible by 1, 2 and 4.
Rewrite sumPrimes so it returns the sum of all prime numbers that are less than or
equal to num.
-
Remember to use Read-Search-Ask if you get stuck. Try to pair program. Write your own code.
Show/Hide sections with changes/issues
- **`Description` section has changed**
```diff
@@ -2,5 +2,4 @@
Check if the predicate (second argument) is truthy on all elements of a collection (first argument).
In other words, you are given an array collection of objects. The predicate pre will be an object property and you need to return true if its value is truthy. Otherwise, return false.
In JavaScript, truthy values are values that translate to true when evaluated in a Boolean context.
-
Remember, you can access object properties through either dot notation or [] notation.
-
Remember to use Read-Search-Ask if you get stuck. Try to pair program. Write your own code.
\ No newline at end of file
+
Remember, you can access object properties through either dot notation or [] notation.
\ No newline at end of file
```
- **The following test(s) `text` do not match:**
**Instructions:** Make sure to also check that the English tests have not been reorderd.
**Test 4**
Show/Hide sections with changes/issues
- **`Description` section has changed**
```diff
@@ -1,5 +1,4 @@
Find the smallest common multiple of the provided parameters that can be evenly divided by both, as well as by all sequential numbers in the range between these parameters.
The range will be an array of two numbers that will not necessarily be in numerical order.
-
For example, if given 1 and 3, find the smallest common multiple of both 1 and 3 that is also evenly divisible by all numbers between 1 and 3. The answer here would be 6.
-
Remember to use Read-Search-Ask if you get stuck. Try to pair program. Write your own code.
\ No newline at end of file
+
For example, if given 1 and 3, find the smallest common multiple of both 1 and 3 that is also evenly divisible by all numbers between 1 and 3. The answer here would be 6.
Show/Hide sections with changes/issues
- **`Description` section has changed**
```diff
@@ -1,3 +1,2 @@
-
Convert the characters &, <, >, " (double quote), and ' (apostrophe), in a string to their corresponding HTML entities.
-
Remember to use Read-Search-Ask if you get stuck. Try to pair program. Write your own code.
\ No newline at end of file
+
Convert the characters &, <, >, " (double quote), and ' (apostrophe), in a string to their corresponding HTML entities.
\ No newline at end of file
```
- **The following test(s) `text` do not match:**
**Instructions:** Make sure to also check that the English tests have not been reorderd.
**Test 1**
Version
Text
Old
```
convertHTML("Dolce & Gabbana") should return Dolce & Gabbana.
```
New
```
`convertHTML("Dolce & Gabbana")` should return `"Dolce & Gabbana"`.
```
Show/Hide sections with changes/issues
- **`Description` section has changed**
```diff
@@ -1,3 +1,2 @@
-
Flatten a nested array. You must account for varying levels of nesting.
-
Remember to use Read-Search-Ask if you get stuck. Try to pair program. Write your own code.
\ No newline at end of file
+
Flatten a nested array. You must account for varying levels of nesting.
\ No newline at end of file
```
- **Number of tests do not match - English: 5 | Chinese: 4**
**Instructions:** Add or delete the applicable tests. It is possible some tests have been rearranged, so make sure each English test has a corresponding Chinese test in the same order
Show/Hide sections with changes/issues
- **`Description` section has changed**
```diff
@@ -2,5 +2,4 @@
Perform a search and replace on the sentence using the arguments provided and return the new sentence.
First argument is the sentence to perform the search and replace on.
Second argument is the word that you will be replacing (before).
-
Third argument is what you will be replacing the second argument with (after).
Note Preserve the case of the first character in the original word when you are replacing it. For example if you mean to replace the word "Book" with the word "dog", it should be replaced as "Dog"
-
Remember to use Read-Search-Ask if you get stuck. Try to pair program. Write your own code.
\ No newline at end of file
+
Third argument is what you will be replacing the second argument with (after).
Note Preserve the case of the first character in the original word when you are replacing it. For example if you mean to replace the word "Book" with the word "dog", it should be replaced as "Dog"
\ No newline at end of file
```
- **Number of tests do not match - English: 6 | Chinese: 5**
**Instructions:** Add or delete the applicable tests. It is possible some tests have been rearranged, so make sure each English test has a corresponding Chinese test in the same order
Show/Hide sections with changes/issues
- **`Description` section has changed**
```diff
@@ -1,4 +1,3 @@
Given the array arr, iterate through and remove each element starting from the first element (the 0 index) until the function func returns true when the iterated element is passed through it.
-
Then return the rest of the array once the condition is satisfied, otherwise, arr should be returned as an empty array.
-
Remember to use Read-Search-Ask if you get stuck. Try to pair program. Write your own code.
\ No newline at end of file
+
Then return the rest of the array once the condition is satisfied, otherwise, arr should be returned as an empty array.
Show/Hide sections with changes/issues
- **`Description` section has changed**
```diff
@@ -3,5 +3,4 @@
For example, addTogether(2, 3) should return 5, and addTogether(2) should return a function.
Calling this returned function with a single argument will then return the sum:
var sumTwoAnd = addTogether(2);
sumTwoAnd(3) returns 5.
-
If either argument isn't a valid number, return undefined.
-
Remember to use Read-Search-Ask if you get stuck. Try to pair program. Write your own code.
\ No newline at end of file
+
If either argument isn't a valid number, return undefined.
\ No newline at end of file
```
- **Number of tests do not match - English: 6 | Chinese: 5**
**Instructions:** Add or delete the applicable tests. It is possible some tests have been rearranged, so make sure each English test has a corresponding Chinese test in the same order
Show/Hide sections with changes/issues
- **`Description` section has changed**
```diff
@@ -1,3 +1,2 @@
-
Compare two arrays and return a new array with any items only found in one of the two given arrays, but not both. In other words, return the symmetric difference of the two arrays.
-
Remember to use Read-Search-Ask if you get stuck. Try to pair program. Write your own code.
Note You can return the array with its elements in any order.
\ No newline at end of file
+
Compare two arrays and return a new array with any items only found in one of the two given arrays, but not both. In other words, return the symmetric difference of the two arrays.
Note You can return the array with its elements in any order.
Show/Hide sections with changes/issues
- **`Description` section has changed**
```diff
@@ -8,6 +8,5 @@ setFullName(firstAndLast)
Run the tests to see the expected output for each method.
The methods that take an argument must accept only one argument and it has to be a string.
-These methods must be the only available means of interacting with the object.
-Remember to use Read-Search-Ask if you get stuck. Try to pair program. Write your own code.
+These methods must be the only available means of interacting with the object.
\ No newline at end of file
```
Show/Hide sections with changes/issues
- **`Description` section has changed**
```diff
@@ -1,4 +1,3 @@
We'll pass you an array of two numbers. Return the sum of those two numbers plus the sum of all the numbers between them. The lowest number will not always come first.
For example, sumAll([4,1]) should return 10 because sum of all the numbers between 1 and 4 (both inclusive) is 10.
-
Remember to use Read-Search-Ask if you get stuck. Try to pair program. Write your own code.
Show/Hide sections with changes/issues
- **`Description` section has changed**
```diff
@@ -1,4 +1,3 @@
Make a function that looks through an array of objects (first argument) and returns an array of all objects that have matching name and value pairs (second argument). Each name and value pair of the source object has to be present in the object from the collection if it is to be included in the returned array.
-
For example, if the first argument is [{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }], and the second argument is { last: "Capulet" }, then you must return the third object from the array (the first argument), because it contains the name and its value, that was passed on as the second argument.
-
Remember to use Read-Search-Ask if you get stuck. Write your own code.
\ No newline at end of file
+
For example, if the first argument is [{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }], and the second argument is { last: "Capulet" }, then you must return the third object from the array (the first argument), because it contains the name and its value, that was passed on as the second argument.
Show/Hide sections with changes/issues
- **`Description` section has changed**
```diff
@@ -1,10 +1,15 @@
So far, you have only been checking if a pattern exists or not within a string. You can also extract the actual matches you found with the .match() method.
-
To use the .match() method, apply the method on a string and pass in the regex inside the parentheses. Here's an example:
"Hello, World!".match(/Hello/);
+
To use the .match() method, apply the method on a string and pass in the regex inside the parentheses.
+
Here's an example:
"Hello, World!".match(/Hello/);
// Returns ["Hello"]
let ourStr = "Regular expressions";
let ourRegex = /expressions/;
ourStr.match(ourRegex);
// Returns ["expressions"]
+
Note that the .match syntax is the "opposite" of the .test method you have been using thus far:
Show/Hide sections with changes/issues
- **Number of tests do not match - English: 3 | Chinese: 1**
**Instructions:** Add or delete the applicable tests. It is possible some tests have been rearranged, so make sure each English test has a corresponding Chinese test in the same order
Show/Hide sections with changes/issues
- **`Instructions` section has changed**
```diff
@@ -1,2 +1,2 @@
-
Write a regex so that it will search for the string "good". Then update the replaceText variable to replace "good" with "okey-dokey".
\ No newline at end of file
+
Write a regex fixRegex using three capture groups that will search for each word in the string "one two three". Then update the replaceText variable to replace "one two three" with the string "three two one" and assign the result to the result variable. Make sure you are utilizing capture groups in the replacement string using the dollar sign ($) syntax.
\ No newline at end of file
```
- **Number of tests do not match - English: 5 | Chinese: 3**
**Instructions:** Add or delete the applicable tests. It is possible some tests have been rearranged, so make sure each English test has a corresponding Chinese test in the same order
```
- **Number of tests do not match - English: 6 | Chinese: 5**
**Instructions:** Add or delete the applicable tests. It is possible some tests have been rearranged, so make sure each English test has a corresponding Chinese test in the same order
Show/Hide sections with changes/issues
- **`Description` section has changed**
```diff
@@ -2,6 +2,6 @@
Usernames are used everywhere on the internet. They are what give users a unique identity on their favorite sites.
You need to check all the usernames in a database. Here are some simple rules that users have to follow when creating their username.
1) Usernames can only use alpha-numeric characters.
-
2) The only numbers in the username have to be at the end. There can be zero or more of them at the end.
+
2) The only numbers in the username have to be at the end. There can be zero or more of them at the end. Username cannot start with the number.
3) Username letters can be lowercase and uppercase.
4) Usernames have to be at least two characters long. A two-character username can only use alphabet letters as characters.
\ No newline at end of file
```
- **Number of tests do not match - English: 12 | Chinese: 11**
**Instructions:** Add or delete the applicable tests. It is possible some tests have been rearranged, so make sure each English test has a corresponding Chinese test in the same order
Show/Hide sections with changes/issues
- **The following test(s) `text` do not match:**
**Instructions:** Make sure to also check that the English tests have not been reorderd.
**Test 2**
Version
Text
Old
```
Your regex should use the shorthand character \S/code> to match all non-whitespace characters.
```
New
```
Your regex should use the shorthand character `\S` to match all non-whitespace characters.
```
Show/Hide sections with changes/issues
- **Number of tests do not match - English: 9 | Chinese: 10**
**Instructions:** Add or delete the applicable tests. It is possible some tests have been rearranged, so make sure each English test has a corresponding Chinese test in the same order
Show/Hide sections with changes/issues
- **`Instructions` section has changed**
```diff
@@ -1,2 +1,2 @@
-
Write a regex and use the appropriate string methods to remove whitespace at the beginning and end of strings.
Note The .trim() method would work here, but you'll need to complete this challenge using regular expressions.
\ No newline at end of file
+
Write a regex and use the appropriate string methods to remove whitespace at the beginning and end of strings.
Note: The String.prototype.trim() method would work here, but you'll need to complete this challenge using regular expressions.
\ No newline at end of file
```
- **The following test(s) `text` do not match:**
**Instructions:** Make sure to also check that the English tests have not been reorderd.
**Test 2**
Version
Text
Old
```
You should not use the .trim() method.
```
New
```
Your solution should not use the `String.prototype.trim()` method.
```
[ ] Understanding the Differences between the freeCodeCamp and Browser ConsoleEdit Chinese | View English
Show/Hide sections with changes/issues
- **`Description` section has changed**
```diff
@@ -1,7 +1,8 @@
You may have noticed that some freeCodeCamp JavaScript challenges include their own console. This console behaves a little differently than the browser console you used in the last challenge.
The following challenge is meant to highlight the main difference between the freeCodeCamp console and your browser console.
-
When you run ordinary JavaScript, the browsers console will display your console.log() statements the exact number of times you requested.
-
The freeCodeCamp console will print your console.log() statements for each test of that challenge, as well as one more time for any function calls that you have in your code.
-
This lends itself to some interesting behavior and might trip you up in the beginning, because a logged value that you expect to see only once may print out many more times.
-
If you would like to see only your single output and not have to worry about running through the test cycles, you can use console.clear() and check the browsers console.
\ No newline at end of file
+
When you run ordinary JavaScript, the browser's console will display your console.log() statements the exact number of times it is called.
+
The freeCodeCamp console will print your console.log() statements a short time after the editor detects a change in the script, as well as during testing.
+
The freeCodeCamp console is cleared before the tests are run and, to avoid spam, only prints the logs during the first test (see the note below for exceptions).
+
If you would like to see every log for every test, run the tests, and open the browser console. If you prefer to use the browser console, and want it to mimic the freeCodeCamp console, place console.clear() before any other console calls, to clear the browser console.
Note:console.logs inside functions are printed to the freeCodeCamp console whenever those functions are called, this can help debugging functions that are called during testing.
+
\ No newline at end of file
```
- **`Instructions` section has changed**
```diff
@@ -1,2 +1,2 @@
-
First, use console.clear() to clear the browser console. After that, use console.log to log the output variable.
\ No newline at end of file
+
First, use console.log to log the output variable. Then, use console.clear to clear the browser console.
Show/Hide sections with changes/issues
- **`Description` section has changed**
```diff
@@ -1,6 +1,6 @@
-
In computer science, data is anything that is meaningful to the computer. JavaScript provides seven different data types which are undefined, null, boolean, string, symbol, number, and object.
-
For example, computers distinguish between numbers, such as the number 12, and strings, such as "12", "dog", or "123 cats", which are collections of characters. Computers can perform mathematical operations on a number, but not on a string.
Variables allow computers to store and manipulate data in a dynamic fashion. They do this by using a "label" to point to the data rather than using the data itself. Any of the seven data types may be stored in a variable.
Variables are similar to the x and y variables you use in mathematics, which means they're a simple name to represent the data we want to refer to. Computer variables differ from mathematical variables in that they can store different values at different times.
+
In computer science, data is anything that is meaningful to the computer. JavaScript provides eight different data types which are undefined, null, boolean, string, symbol, bigint, number, and object.
+
For example, computers distinguish between numbers, such as the number 12, and strings, such as "12", "dog", or "123 cats", which are collections of characters. Computers can perform mathematical operations on a number, but not on a string.
Variables allow computers to store and manipulate data in a dynamic fashion. They do this by using a "label" to point to the data rather than using the data itself. Any of the eight data types may be stored in a variable.
Variables are similar to the x and y variables you use in mathematics, which means they're a simple name to represent the data we want to refer to. Computer variables differ from mathematical variables in that they can store different values at different times.
We tell JavaScript to create or declare a variable by putting the keyword var in front of it, like so:
var ourName;
creates a variable called ourName. In JavaScript we end statements with semicolons.
```
- **`Instructions` section has changed**
```diff
@@ -1,2 +1,2 @@
-
Use the var keyword to create a variable called myName.
Hint Look at the ourName example if you get stuck.
\ No newline at end of file
+
Use the var keyword to create a variable called myName.
Hint Look at the ourName example above if you get stuck.
Show/Hide sections with changes/issues
- **`Description` section has changed**
```diff
@@ -1,16 +1,3 @@
-
In a previous challenge, 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 base case. 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 recursive call which executes the original function with different arguments. If the function is written correctly, eventually the base case will be reached.
-
For example, say you want to write a recursive function that returns an array containing the numbers 1 through n. This function will need to accept an argument n representing the final number. Then it will need to call itself with progressively smaller values of n until it reaches 1. You could write the function as follows:
At first this is counterintuitive since the value of ndecreases, 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, count(n - 1) has already been evaluated and returned [1, 2, ..., n - 1].
+
Continuing from the previous challenge, we provide you another opportunity to create a recursive function to solve a problem.
\ No newline at end of file
```
- **The following test(s) `text` do not match:**
**Instructions:** Make sure to also check that the English tests have not been reorderd.
**Test 6**
Version
Text
Old
```
rangeOfNumbers(4, 4) should should return [4].
```
New
```
`rangeOfNumbers(4, 4)` should return `[4]`.
```
Show/Hide sections with changes/issues
- **The following test(s) `text` do not match:**
**Instructions:** Make sure to also check that the English tests have not been reorderd.
**Test 1**
Version
Text
Old
```
"Kristian", "lastName" should return "Vos"
```
New
```
`lookUpProfile("Kristian", "lastName")` should return `"Vos"`
```
**Test 2**
Version
Text
Old
```
"Sherlock", "likes" should return ["Intriguing Cases", "Violin"]
```
New
```
`lookUpProfile("Sherlock", "likes")` should return `["Intriguing Cases", "Violin"]`
```
**Test 3**
Version
Text
Old
```
"Harry","likes" should return an array
```
New
```
`lookUpProfile("Harry", "likes")` should return an array
```
**Test 4**
Version
Text
Old
```
"Bob", "number" should return "No such contact"
```
New
```
`lookUpProfile("Bob", "number")` should return "No such contact"
```
**Test 5**
Version
Text
Old
```
"Bob", "potato" should return "No such contact"
```
New
```
`lookUpProfile("Bob", "potato")` should return "No such contact"
```
**Test 6**
Version
Text
Old
```
"Akira", "address" should return "No such property"
```
New
```
`lookUpProfile("Akira", "address")` should return "No such property"
```
Show/Hide sections with changes/issues
- **The following test(s) `text` do not match:**
**Instructions:** Make sure to also check that the English tests have not been reorderd.
**Test 2**
Version
Text
Old
```
You should be using Math.random to generate a random number.
```
New
```
You should use `Math.random` to generate a random number.
```
Show/Hide sections with changes/issues
- **`Description` section has changed**
```diff
@@ -1,4 +1,4 @@
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, all function calls will be resolved before the return executes, so we can return the value of the Math.random() function.
\ No newline at end of file
+
Note Like Storing Values with the Equal Operator, all function calls will be resolved before the return executes, so we can return the value of the Math.random() function.
Show/Hide sections with changes/issues
- **`Description` section has changed**
```diff
@@ -1,2 +1,8 @@
-
Not only can you shift elements off of the beginning of an array, you can also unshift elements to the beginning of an array i.e. add elements in front of the array.
.unshift() works exactly like .push(), but instead of adding the element at the end of the array, unshift() adds the element at the beginning of the array.
\ No newline at end of file
+
Not only can you shift elements off of the beginning of an array, you can also unshift elements to the beginning of an array i.e. add elements in front of the array.
.unshift() works exactly like .push(), but instead of adding the element at the end of the array, unshift() adds the element at the beginning of the array.
Example:
+
var ourArray = ["Stimpson", "J", "cat"];
+ourArray.shift(); // ourArray now equals ["J", "cat"]
+ourArray.unshift("Happy");
+// ourArray now equals ["Happy", "J", "cat"]
+
Show/Hide sections with changes/issues
- **`Description` section has changed**
```diff
@@ -1,8 +1,8 @@
-
In JavaScript, you can store a value in a variable with the assignment operator.
myVariable = 5;
+
In JavaScript, you can store a value in a variable with the assignment operator (=).
myVariable = 5;
This assigns the Number value 5 to myVariable.
-
Assignment always goes from right to left. Everything to the right of the = operator is resolved before the value is assigned to the variable to the left of the operator.
myVar = 5;
-myNum = myVar;
+
If there are any calculations to the right of the = operator, those are performed before the value is assigned to the variable on the left of the operator.
var myVar;
+myVar = 5;
-
This assigns 5 to myVar and then resolves myVar to 5 again and assigns it to myNum.
+
First, this code creates a variable named myVar. Then, the code assigns 5 to myVar. Now, if myVar appears again in the code, the program will treat it as if it is 5.
\ No newline at end of file
```
- **`Instructions` section has changed**
```diff
@@ -1,3 +1,2 @@
-
Assign the value 7 to variable a.
-
Assign the contents of a to variable b.
\ No newline at end of file
+
Assign the value 7 to variable a.
\ No newline at end of file
```
- **Number of tests do not match - English: 2 | Chinese: 4**
**Instructions:** Add or delete the applicable tests. It is possible some tests have been rearranged, so make sure each English test has a corresponding Chinese test in the same order
Show/Hide sections with changes/issues
- **`Instructions` section has changed**
```diff
@@ -1,3 +1,3 @@
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 "name" is a string, "legs" and "tails" are numbers, and "friends" is an array.
\ No newline at end of file
+
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.
Show/Hide sections with changes/issues
- **`Description` section has changed**
```diff
@@ -1,11 +1,12 @@
-
You are given a JSON object representing a part of your musical album collection. Each album has several properties and a unique id number as its key. Not all albums have complete information.
-
Write a function which takes an album's id (like 2548), a property prop (like "artist" or "tracks"), and a value (like "Addicted to Love") to modify the data in this collection.
-
If prop isn't "tracks" and value isn't empty (""), update or set the value for that record album's property.
-
Your function must always return the entire collection object.
-
There are several rules for handling incomplete data:
-
If prop is "tracks" but the album doesn't have a "tracks" property, create an empty array before adding the new value to the album's corresponding property.
-
If prop is "tracks" and value isn't empty (""), push the value onto the end of the album's existing tracks array.
-
If value is empty (""), delete the given prop property from the album.
You may refer back to Manipulating Complex Objects Introducing JavaScript Object Notation (JSON) for a refresher.
\ No newline at end of file
+
You are given a JSON object representing a part of your musical album collection. Each album has a unique id number as its key and several other properties. Not all albums have complete information.
+
You start with an updateRecords function that takes an object like collection, an id, a prop (like artist or tracks), and a value. Complete the function using the rules below to modify the object passed to the function.
+
+
Your function must always return the entire object.
+
If prop isn't tracks and value isn't an empty string, update or set that album's prop to value.
+
If prop is tracks but the album doesn't have a tracks property, create an empty array and add value to it.
+
If prop is tracks and value isn't an empty string, add value to the end of the album's existing tracks array.
+
If value is an empty string, delete the given prop property from the album.
+
+
Note: A copy of the collection object is used for the tests.
+
\ No newline at end of file
```
- **Number of tests do not match - English: 7 | Chinese: 8**
**Instructions:** Add or delete the applicable tests. It is possible some tests have been rearranged, so make sure each English test has a corresponding Chinese test in the same order
Show/Hide sections with changes/issues
- **`Description` section has changed**
```diff
@@ -19,7 +19,7 @@
: "b is greater";
}
-
However, this should be used with care as using multiple conditional operators without proper indentation may make your code hard to read. For example:
+
It is considered best practice to format multiple conditional operators such that each condition is on a separate line, as shown above. Using multiple conditional operators without proper indentation may make your code hard to read. For example:
function findGreaterOrEqual(a, b) {
return (a === b) ? "a and b are equal" : (a > b) ? "a is greater" : "b is greater";
}
```
- **`Instructions` section has changed**
```diff
@@ -1,2 +1,2 @@
-
Use multiple conditional operators in the checkSign function to check if a number is positive, negative or zero. The function should return "positive", "negative" or "zero".
\ No newline at end of file
+
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".
\ No newline at end of file
```
- **The following test(s) `text` do not match:**
**Instructions:** Make sure to also check that the English tests have not been reorderd.
**Test 2**
Version
Text
Old
```
myVar = myVar + 1; should be changed.
```
New
```
You should not use the assignment operator.
```
Show/Hide sections with changes/issues
- **`Description` section has changed**
```diff
@@ -1,3 +1,17 @@
-
Continuing from the previous challenge, we provide you another opportunity to create a recursive function to solve a problem.
+
In a previous challenge, 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 base case. 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 recursive call which executes the original function with different arguments. If the function is written correctly, eventually the base case will be reached.
+
For example, say you want to write a recursive function that returns an array containing the numbers 1 through n. This function will need to accept an argument, n, representing the final number. Then it will need to call itself with progressively smaller values of n until it reaches 1. You could write the function as follows:
At first, this seems counterintuitive since the value of ndecreases, 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].
\ No newline at end of file
```
- **`Instructions` section has changed**
```diff
@@ -1,5 +1,5 @@
-
We have defined a function called countdown with two parameters. The function should take an array in the myArray parameter and append the numbers n through 1 based on the n parameter.
-For example, calling this function with n = 5 will pad the array with the numbers [5, 4, 3, 2, 1] inside of it.
+
We have defined a function called countdown with one parameter (n). The function should use recursion to return an array containing the integers n through 1 based on the n parameter. If the function is called with a number less than 1, the function should return an empty array.
+For example, calling this function with n = 5 should return the array [5, 4, 3, 2, 1].
Your function must use recursion by calling itself and must not use loops of any kind.
\ No newline at end of file
```
- **The following test(s) `text` do not match:**
**Instructions:** Make sure to also check that the English tests have not been reorderd.
**Test 1**
Version
Text
Old
```
After calling countdown(myArray, -1), myArray should be empty.
```
New
```
`countdown(-1)` should return an empty array.
```
**Test 2**
Version
Text
Old
```
After calling countdown(myArray, 10), myArray should contain [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
```
Show/Hide sections with changes/issues
- **`Description` section has changed**
```diff
@@ -1,5 +1,6 @@
-
If the break statement is omitted from a switch statement's case, the following case statement(s) are executed until a break is encountered. If you have multiple inputs with the same output, you can represent them in a switch statement like this:
switch(val) {
+
If the break statement is omitted from a switch statement's case, the following case statement(s) are executed until a break is encountered. If you have multiple inputs with the same output, you can represent them in a switch statement like this:
var result = "";
+switch(val) {
case 1:
case 2:
case 3:
```
Show/Hide sections with changes/issues
- **`Description` section has changed**
```diff
@@ -1,2 +1,8 @@
-
Just as we can build a string over multiple lines out of string literals, we can also append variables to a string using the plus equals (+=) operator.
\ No newline at end of file
+
Just as we can build a string over multiple lines out of string literals, we can also append variables to a string using the plus equals (+=) operator.
Example:
+
var anAdjective = "awesome!";
+var ourStr = "freeCodeCamp is ";
+ourStr += anAdjective;
+// ourStr is now "freeCodeCamp is awesome!"
+
+
\ No newline at end of file
```
- **`Instructions` section has changed**
```diff
@@ -1,2 +1,2 @@
-
Set someAdjective and append it to myStr using the += operator.
\ No newline at end of file
+
Set someAdjective to a string of at least 3 characters and append it to myStr using the += operator.
Show/Hide sections with changes/issues
- **`Description` section has changed**
```diff
@@ -1,2 +1,7 @@
-
Sometimes you will need to build a string, Mad Libs style. By using the concatenation operator (+), you can insert one or more variables into a string you're building.
\ No newline at end of file
+
Sometimes you will need to build a string, Mad Libs style. By using the concatenation operator (+), you can insert one or more variables into a string you're building.
Example:
+
var ourName = "freeCodeCamp";
+var ourStr = "Hello, our name is " + ourName + ", how are you?";
+// ourStr is now "Hello, our name is freeCodeCamp, how are you?"
+
Show/Hide sections with changes/issues
- **`Description` section has changed**
```diff
@@ -1,21 +1,21 @@
-
Recursion is the concept that a function can be expressed in terms of itself. To help understand this, start by thinking about the following task: multiply the elements from 0 to n inclusive in an array to create the product of those elements. Using a for loop, you could do this:
function multiply(arr, n) {
- var product = arr[0];
- for (var i = 1; i <= n; i++) {
+
Recursion is the concept that a function can be expressed in terms of itself. To help understand this, start by thinking about the following task: multiply the first n elements of an array to create the product of those elements. Using a for loop, you could do this:
function multiply(arr, n) {
+ var product = 1;
+ for (var i = 0; i < n; i++) {
product *= arr[i];
}
return product;
}
-
However, notice that multiply(arr, n) == multiply(arr, n - 1) * arr[n]. That means you can rewrite multiply in terms of itself and never need to use a loop.
+
However, notice that multiply(arr, n) == multiply(arr, n - 1) * arr[n - 1]. That means you can rewrite multiply in terms of itself and never need to use a loop.
function multiply(arr, n) {
if (n <= 0) {
- return arr[0];
+ return 1;
} else {
- return multiply(arr, n - 1) * arr[n];
+ return multiply(arr, n - 1) * arr[n - 1];
}
}
-
The recursive version of multiply breaks down like this. In the base case, where n <= 0, it returns the result, arr[0]. For larger values of n, it calls itself, but with n - 1. That function call is evaluated in the same way, calling multiply again until n = 0. At this point, all the functions can return and the original multiply returns the answer.
+
The recursive version of multiply breaks down like this. In the base case, where n <= 0, it returns 1. For larger values of n, it calls itself, but with n - 1. That function call is evaluated in the same way, calling multiply again until n <= 0. At this point, all the functions can return and the original multiply returns the answer.
Note: Recursive functions must have a base case when they return without calling the function again (in this example, when n <= 0), otherwise they can never finish executing.
\ No newline at end of file
```
- **`Instructions` section has changed**
```diff
@@ -1,3 +1,3 @@
-
Write a recursive function, sum(arr, n), that returns the sum of the elements from 0 to n inclusive in an array arr.
+
Write a recursive function, sum(arr, n), that returns the sum of the first n elements of an array arr.
\ No newline at end of file
```
- **Number of tests do not match - English: 5 | Chinese: 4**
**Instructions:** Add or delete the applicable tests. It is possible some tests have been rearranged, so make sure each English test has a corresponding Chinese test in the same order
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.
+
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.
Show/Hide sections with changes/issues
- **`Description` section has changed**
```diff
@@ -1,6 +1,6 @@
There are many comparison operators in JavaScript. All of these operators return a boolean true or false value.
-
The most basic operator is the equality operator ==. The equality operator compares two values and returns true if they're equivalent or false if they are not. Note that equality is different from assignment (=), which assigns the value at the right of the operator to a variable in the left.
function equalityTest(myVal) {
+
The most basic operator is the equality operator ==. The equality operator compares two values and returns true if they're equivalent or false if they are not. Note that equality is different from assignment (=), which assigns the value on the right of the operator to a variable on the left.
function equalityTest(myVal) {
if (myVal == 10) {
return "Equal";
}
```
[ ] Use Bracket Notation to Find the Nth-to-Last Character in a StringEdit Chinese | View English
Show/Hide sections with changes/issues
- **`Description` section has changed**
```diff
@@ -1,4 +1,8 @@
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 var firstName = "Charles" string by using firstName[firstName.length - 3]
+
Example:
+
var firstName = "Charles";
+var thirdToLastLetter = firstName[firstName.length - 3]; // thirdToLastLetter is "l"
+
\ No newline at end of file
```
- **`Instructions` section has changed**
```diff
@@ -1,2 +1,2 @@
-
Use bracket notation to find the second-to-last character in the lastName string.
Hint Try looking at the thirdToLastLetterOfFirstName variable declaration if you get stuck.
\ No newline at end of file
+
Use bracket notation to find the second-to-last character in the lastName string.
Hint: Try looking at the example above if you get stuck.
Show/Hide sections with changes/issues
- **`Description` section has changed**
```diff
@@ -1,5 +1,5 @@
-
Instead of generating a random number between zero and a given number like we did before, we can generate a random number that falls within a range of two specific numbers.
+
Instead of generating a random whole number between zero and a given number like we did before, we can generate a random whole number that falls within a range of two specific numbers.
To do this, we'll define a minimum number min and a maximum number max.
Here's the formula we'll use. Take a moment to read it and try to understand what this code is doing:
Math.floor(Math.random() * (max - min + 1)) + min
\ No newline at end of file
```
- **`Instructions` section has changed**
```diff
@@ -1,2 +1,2 @@
-
Create a function called randomRange that takes a range myMin and myMax and returns a random number that's greater than or equal to myMin, and is less than or equal to myMax, inclusive.
\ No newline at end of file
+
Create a function called randomRange that takes a range myMin and myMax and returns a random whole number that's greater than or equal to myMin, and is less than or equal to myMax, inclusive.
\ No newline at end of file
```
- **Number of tests do not match - English: 7 | Chinese: 6**
**Instructions:** Add or delete the applicable tests. It is possible some tests have been rearranged, so make sure each English test has a corresponding Chinese test in the same order
Show/Hide sections with changes/issues
- **`Description` section has changed**
```diff
@@ -1,2 +1,7 @@
-
We can also use the += operator to concatenate 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.
\ No newline at end of file
+
We can also use the += operator to concatenate 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.
Example:
+
var ourStr = "I come first. ";
+ourStr += "I come second.";
+// ourStr is now "I come first. I come second."
+
Show/Hide sections with changes/issues
- **`Description` section has changed**
```diff
@@ -1,5 +1,5 @@
-
A common task in JavaScript is to iterate through the contents of an array. One way to do that is with a for loop. This code will output each element of the array arr to the console:
var arr = [10,9,8,7,6];
+
A common task in JavaScript is to iterate through the contents of an array. One way to do that is with a for loop. This code will output each element of the array arr to the console:
var arr = [10, 9, 8, 7, 6];
for (var i = 0; i < arr.length; i++) {
console.log(arr[i]);
}
```
- **The following test(s) `text` do not match:**
**Instructions:** Make sure to also check that the English tests have not been reorderd.
**Test 4**
Version
Text
Old
```
You should not set total to 20 directly.
```
New
```
You should not attempt to directly assign the value 20 to `total`.
```
Show/Hide sections with changes/issues
- **`Description` section has changed**
```diff
@@ -1,4 +1,4 @@
-
If you'll recall from our discussion of Storing Values with the Assignment Operator, everything to the right of the equal sign is resolved before the value is assigned. This means we can take the return value of a function and assign it to a variable.
+
If you'll recall from our discussion of Storing Values with the Assignment Operator, everything to the right of the equal sign is resolved before the value is assigned. This means we can take the return value of a function and assign it to a variable.
Assume we have pre-defined a function sum which adds two numbers together, then:
ourSum = sum(5, 12);
will call sum function, which returns a value of 17 and assigns it to ourSum variable.
Show/Hide sections with changes/issues
- **`Description` section has changed**
```diff
@@ -1,4 +1,8 @@
Bracket notation 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 Zero-based 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].
\ No newline at end of file
+
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:
+
var firstName = "Charles";
+var firstLetter = firstName[0]; // firstLetter is "C"
+
+
\ No newline at end of file
```
- **`Instructions` section has changed**
```diff
@@ -1,2 +1,2 @@
-
Use bracket notation to find the first character in the lastName variable and assign it to firstLetterOfLastName.
Hint Try looking at the firstLetterOfFirstName variable declaration if you get stuck.
\ No newline at end of file
+
Use bracket notation to find the first character in the lastName variable and assign it to firstLetterOfLastName.
Hint: Try looking at the example above if you get stuck.
Show/Hide sections with changes/issues
- **`Instructions` section has changed**
```diff
@@ -1,2 +1,2 @@
-
Modify the function checkObj to test myObj for checkProp. If the property is found, return that property's value. If not, return "Not Found".
\ No newline at end of file
+
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".
\ No newline at end of file
```
- **Number of tests do not match - English: 6 | Chinese: 3**
**Instructions:** Add or delete the applicable tests. It is possible some tests have been rearranged, so make sure each English test has a corresponding Chinese test in the same order
Show/Hide sections with changes/issues
- **`Instructions` section has changed**
```diff
@@ -1,2 +1,4 @@
-
Declare a local variable myVar inside myLocalScope. Run the tests and then follow the instructions commented out in the editor.
Hint Refreshing the page may help if you get stuck.
\ No newline at end of file
+
The editor has two console.logs 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.
How is this useful? You may recall the hasOwnProperty method from a previous challenge:
let duck = new Bird("Donald");
-duck.hasOwnProperty("name"); // => true
+duck.hasOwnProperty("name"); // yields true
The hasOwnProperty method is defined in Object.prototype, which can be accessed by Bird.prototype, which can then be accessed by duck. This is an example of the prototype chain.
In this prototype chain, Bird is the supertype for duck, while duck is the subtype. Object is a supertype for both Bird and duck.
```
Show/Hide sections with changes/issues
- **Number of tests do not match - English: 7 | Chinese: 5**
**Instructions:** Add or delete the applicable tests. It is possible some tests have been rearranged, so make sure each English test has a corresponding Chinese test in the same order
Show/Hide sections with changes/issues
- **`Description` section has changed**
```diff
@@ -2,5 +2,4 @@
Return true if the string in the first element of the array contains all of the letters of the string in the second element of the array.
For example, ["hello", "Hello"], should return true because all of the letters in the second string are present in the first, ignoring case.
The arguments ["hello", "hey"] should return false because the string "hello" does not contain a "y".
-
Lastly, ["Alien", "line"], should return true because all of the letters in "line" are present in "Alien".
-
Remember to use Read-Search-Ask if you get stuck. Write your own code.
\ No newline at end of file
+
Lastly, ["Alien", "line"], should return true because all of the letters in "line" are present in "Alien".
\ No newline at end of file
```
- **The following test(s) `text` do not match:**
**Instructions:** Make sure to also check that the English tests have not been reorderd.
**Test 10**
Version
Text
Old
```
mutation(["ate", "date"] should return false should return false.
```
New
```
`mutation(["ate", "date"]` should return false.
```
- **Number of tests do not match - English: 12 | Chinese: 9**
**Instructions:** Add or delete the applicable tests. It is possible some tests have been rearranged, so make sure each English test has a corresponding Chinese test in the same order
Show/Hide sections with changes/issues
- **`Description` section has changed**
```diff
@@ -1,4 +1,3 @@
Check if a string (first argument, str) ends with the given target string (second argument, target).
-
This challenge can be solved with the .endsWith() method, which was introduced in ES2015. But for the purpose of this challenge, we would like you to use one of the JavaScript substring methods instead.
-
Remember to use Read-Search-Ask if you get stuck. Write your own code.
\ No newline at end of file
+
This challenge can be solved with the .endsWith() method, which was introduced in ES2015. But for the purpose of this challenge, we would like you to use one of the JavaScript substring methods instead.
\ No newline at end of file
```
- **The following test(s) `text` do not match:**
**Instructions:** Make sure to also check that the English tests have not been reorderd.
**Test 7**
Version
Text
Old
```
confirmEnding("Open sesame", "pen") should return false.
```
New
```
`confirmEnding("Open sesame", "sage")` should return false.
```
Show/Hide sections with changes/issues
- **`Description` section has changed**
```diff
@@ -1,3 +1,2 @@
-
Truncate a string (first argument) if it is longer than the given maximum string length (second argument). Return the truncated string with a ... ending.
-
Remember to use Read-Search-Ask if you get stuck. Write your own code.
\ No newline at end of file
+
Truncate a string (first argument) if it is longer than the given maximum string length (second argument). Return the truncated string with a ... ending.
Show/Hide sections with changes/issues
- **`Description` section has changed**
```diff
@@ -1,3 +1,2 @@
-
Repeat a given string str (first argument) for num times (second argument). Return an empty string if num is not a positive number.
-
Remember to use Read-Search-Ask if you get stuck. Write your own code.
\ No newline at end of file
+
Repeat a given string str (first argument) for num times (second argument). Return an empty string if num is not a positive number. For the purpose of this challenge, do not use the built-in .repeat() method.
\ No newline at end of file
```
- **Number of tests do not match - English: 8 | Chinese: 7**
**Instructions:** Add or delete the applicable tests. It is possible some tests have been rearranged, so make sure each English test has a corresponding Chinese test in the same order
Show/Hide sections with changes/issues
- **`Description` section has changed**
```diff
@@ -1,5 +1,4 @@
Return the lowest index at which a value (second argument) should be inserted into an array (first argument) once it has been sorted. The returned value should be a number.
For example, getIndexToIns([1,2,3,4], 1.5) should return 1 because it is greater than 1 (index 0), but less than 2 (index 1).
-
Likewise, getIndexToIns([20,3,5], 19) should return 2 because once the array has been sorted it will look like [3,5,20] and 19 is less than 20 (index 2) and greater than 5 (index 1).
-
Remember to use Read-Search-Ask if you get stuck. Write your own code.
\ No newline at end of file
+
Likewise, getIndexToIns([20,3,5], 19) should return 2 because once the array has been sorted it will look like [3,5,20] and 19 is less than 20 (index 2) and greater than 5 (index 1).
Show/Hide sections with changes/issues
- **`Description` section has changed**
```diff
@@ -1,5 +1,4 @@
Remove all falsy values from an array.
Falsy values in JavaScript are false, null, 0, "", undefined, and NaN.
-
Hint: Try converting each value to a Boolean.
-
Remember to use Read-Search-Ask if you get stuck. Write your own code.
\ No newline at end of file
+
Hint: Try converting each value to a Boolean.
\ No newline at end of file
```
- **The following test(s) `text` do not match:**
**Instructions:** Make sure to also check that the English tests have not been reorderd.
**Test 4**
Show/Hide sections with changes/issues
- **`Description` section has changed**
```diff
@@ -1,3 +1,3 @@
-
Create a function that looks through an array (first argument) and returns the first element in the array that passes a truth test (second argument). If no element passes the test, return undefined.
-
Remember to use Read-Search-Ask if you get stuck. Try to pair program. Write your own code.
\ No newline at end of file
+
Create a function that looks through an array arr and returns the first element in it that passes a 'truth test'. This means that given an element x, the 'truth test' is passed if func(x) is true. If no element passes the test, return undefined.
Show/Hide sections with changes/issues
- **The following test(s) `text` do not match:**
**Instructions:** Make sure to also check that the English tests have not been reorderd.
**Test 1**
Version
Text
Old
```
htmlColorNames should return ["DarkSalmon", "BlanchedAlmond", "LavenderBlush", "PaleTurqoise", "FireBrick"]
```
New
```
`htmlColorNames` should return `["DarkSalmon", "BlanchedAlmond", "LavenderBlush", "PaleTurquoise", "FireBrick"]`
```
Show/Hide sections with changes/issues
- **`Description` section has changed**
```diff
@@ -1,18 +1,29 @@
-
At their most basic, objects are just collections of key-value pairs, or in other words, pieces of data mapped to unique identifiers that we call properties or keys. Let's take a look at a very simple example:
At their most basic, objects are just collections of key-value pairs. In other words, they are pieces of data (values) mapped to unique identifiers called properties (keys). Take a look at an example:
The above code defines an object called FCC_User that has four properties, each of which map to a specific value. If we wanted to know the number of followersFCC_User has, we can access that property by writing:
-
let userData = FCC_User.followers;
-// userData equals 572
+
The above code defines a Tekken video game character object called tekkenCharacter. It has three properties, each of which map to a specific value. If you want to add an additional property, such as "origin", it can be done by assigning origin to the object:
+
tekkenCharacter.origin = 'South Korea';
-
This is called dot notation. Alternatively, we can also access the property with brackets, like so:
-
let userData = FCC_User['followers'];
-// userData equals 572
+
This uses dot notation. If you were to observe the tekkenCharacter object, it will now include the origin property. Hwoarang also had distinct orange hair. You can add this property with bracket notation by doing:
+
tekkenCharacter['hair color'] = 'dyed orange';
+
+
Bracket notation is required if your property has a space in it or if you want to use a variable to name the property. In the above case, the property is enclosed in quotes to denote it as a string and will be added exactly as shown. Without quotes, it will be evaluated as a variable and the name of the property will be whatever value the variable is. Here's an example with a variable:
Notice that with bracket notation, we enclosed followers in quotes. This is because the brackets actually allow us to pass a variable in to be evaluated as a property name (hint: keep this in mind for later!). Had we passed followers in without the quotes, the JavaScript engine would have attempted to evaluate it as a variable, and a ReferenceError: followers is not defined would have been thrown.
\ No newline at end of file
```
- **`Instructions` section has changed**
```diff
@@ -1,2 +1,2 @@
-
Using the same syntax, we can also add new key-value pairs to objects. We've created a foods object with three entries. Add three more entries: bananas with a value of 13, grapes with a value of 35, and strawberries with a value of 27.
\ No newline at end of file
+
A foods object has been created with three entries. Using the syntax of your choice, add three more entries to it: bananas with a value of 13, grapes with a value of 35, and strawberries with a value of 27.
nestedObject has three unique keys: id, whose value is a number, date whose value is a string, and data, whose value is an object which has yet another object nested within it. While structures can quickly become complex, we can still use the same notations to access the information we need.
+
nestedObject has three properties: id (value is a number), date (value is a string), and data (value is an object with its nested structure). While structures can quickly become complex, we can still use the same notations to access the information we need. To assign the value 10 to the busy property of the nested onlineStatus object, we use dot notation to reference the property:
+
nestedObject.data.onlineStatus.busy = 10;
+
\ No newline at end of file
```
- **`Instructions` section has changed**
```diff
@@ -1,2 +1,2 @@
-
Here we've defined an object, userActivity, which includes another object nested within it. You can modify properties on this nested object in the same way you modified properties in the last challenge. Set the value of the online key to 45.
\ No newline at end of file
+
Here we've defined an object userActivity, which includes another object nested within it. Set the value of the online key to 45.
Show/Hide sections with changes/issues
- **Number of tests do not match - English: 6 | Chinese: 5**
**Instructions:** Add or delete the applicable tests. It is possible some tests have been rearranged, so make sure each English test has a corresponding Chinese test in the same order
Show/Hide sections with changes/issues
- **`Description` section has changed**
```diff
@@ -1,5 +1,5 @@
-
The next method we will cover is slice(). slice(), rather than modifying an array, copies, or extracts, a given number of elements to a new array, leaving the array it is called upon untouched. slice() takes only 2 parameters — the first is the index at which to begin extraction, and the second is the index at which to stop extraction (extraction will occur up to, but not including the element at this index). Consider this:
let weatherConditions = ['rain', 'snow', 'sleet', 'hail', 'clear'];
+
The next method we will cover is slice(). Rather than modifying an array, slice() copies or extracts a given number of elements to a new array, leaving the array it is called upon untouched. slice() takes only 2 parameters — the first is the index at which to begin extraction, and the second is the index at which to stop extraction (extraction will occur up to, but not including the element at this index). Consider this:
let weatherConditions = ['rain', 'snow', 'sleet', 'hail', 'clear'];
let todaysWeather = weatherConditions.slice(1, 3);
// todaysWeather equals ['snow', 'sleet'];
```
Show/Hide sections with changes/issues
- **`Description` section has changed**
```diff
@@ -3,6 +3,6 @@
In practice, we can use the spread operator to copy an array like so:
let thisArray = [true, true, undefined, false, null];
let thatArray = [...thisArray];
// thatArray equals [true, true, undefined, false, null]
-// thisArray remains unchanged, and is identical to thatArray
+// thisArray remains unchanged and thatArray contains the same elements as thisArray
Show/Hide sections with changes/issues
- **`Description` section has changed**
```diff
@@ -2,5 +2,4 @@
One of the simplest and most widely known ciphers is a Caesar cipher, also known as a shift cipher. In a shift cipher the meanings of the letters are shifted by some set amount.
A common modern use is the ROT13 cipher, where the values of the letters are shifted by 13 places. Thus 'A' ↔ 'N', 'B' ↔ 'O' and so on.
Write a function which takes a ROT13 encoded string as input and returns a decoded string.
-
All letters will be uppercase. Do not transform any non-alphabetic character (i.e. spaces, punctuation), but do pass them on.
-
Remember to use Read-Search-Ask if you get stuck. Try to pair program. Write your own code.
\ No newline at end of file
+
All letters will be uppercase. Do not transform any non-alphabetic character (i.e. spaces, punctuation), but do pass them on.
Show/Hide sections with changes/issues
- **`Description` section has changed**
```diff
@@ -2,5 +2,4 @@
Return true if the given string is a palindrome. Otherwise, return false.
A palindrome is a word or sentence that's spelled the same way both forward and backward, ignoring punctuation, case, and spacing.
Note You'll need to remove all non-alphanumeric characters (punctuation, spaces and symbols) and turn everything into the same case (lower or upper case) in order to check for palindromes.
We'll pass strings with varying formats, such as "racecar", "RaceCar", and "race CAR" among others.
-
We'll also pass strings with special symbols, such as "2A3*3a2", "2A3 3a2", and "2_A3*3#A2".
-
Remember to use Read-Search-Ask if you get stuck. Write your own code.
\ No newline at end of file
+
We'll also pass strings with special symbols, such as "2A3*3a2", "2A3 3a2", and "2_A3*3#A2".
Show/Hide sections with changes/issues
- **`Description` section has changed**
```diff
@@ -3,6 +3,18 @@
The checkCashRegister() function should always return an object with a status key and a change key.
Return {status: "INSUFFICIENT_FUNDS", change: []} if cash-in-drawer is less than the change due, or if you cannot return the exact change.
Return {status: "CLOSED", change: [...]} with cash-in-drawer as the value for the key change if it is equal to the change due.
-
Otherwise, return {status: "OPEN", change: [...]}, with the change due in coins and bills, sorted in highest to lowest order, as the value of the change key.
-
Remember to use Read-Search-Ask if you get stuck. Try to pair program. Write your own code.
Currency Unit
Amount
Penny
/bin/sh.01 (PENNY)
Nickel
/bin/sh.05 (NICKEL)
Dime
/bin/sh.1 (DIME)
Quarter
/bin/sh.25 (QUARTER)
Dollar
(DOLLAR)
Five Dollars
(FIVE)
Ten Dollars
(TEN)
Twenty Dollars
(TWENTY)
One-hundred Dollars
(ONE HUNDRED)
+
Otherwise, return {status: "OPEN", change: [...]}, with the change due in coins and bills, sorted in highest to lowest order, as the value of the change key.
Currency Unit
Amount
Penny
/bin/sh.01 (PENNY)
Nickel
/bin/sh.05 (NICKEL)
Dime
/bin/sh.1 (DIME)
Quarter
/bin/sh.25 (QUARTER)
Dollar
(ONE)
Five Dollars
(FIVE)
Ten Dollars
(TEN)
Twenty Dollars
(TWENTY)
One-hundred Dollars
(ONE HUNDRED)
+
See below for an example of a cash-in-drawer array:
Show/Hide sections with changes/issues
- **`Description` section has changed**
```diff
@@ -1,5 +1,4 @@
Return true if the passed string looks like a valid US phone number.
The user may fill out the form field any way they choose as long as it has the format of a valid US number. The following are examples of valid formats for US numbers (refer to the tests below for other variants):
For this challenge you will be presented with a string such as 800-692-7753 or 8oo-six427676;laskdjf. Your job is to validate or reject the US phone number based on any combination of the formats provided above. The area code is required. If the country code is provided, you must confirm that the country code is 1. Return true if the string is a valid US phone number; otherwise return false.
-
Remember to use Read-Search-Ask if you get stuck. Try to pair program. Write your own code.
\ No newline at end of file
+
For this challenge you will be presented with a string such as 800-692-7753 or 8oo-six427676;laskdjf. Your job is to validate or reject the US phone number based on any combination of the formats provided above. The area code is required. If the country code is provided, you must confirm that the country code is 1. Return true if the string is a valid US phone number; otherwise return false.
Show/Hide sections with changes/issues
- **Number of tests do not match - English: 5 | Chinese: 6**
**Instructions:** Add or delete the applicable tests. It is possible some tests have been rearranged, so make sure each English test has a corresponding Chinese test in the same order
Show/Hide sections with changes/issues
- **Number of tests do not match - English: 3 | Chinese: 2**
**Instructions:** Add or delete the applicable tests. It is possible some tests have been rearranged, so make sure each English test has a corresponding Chinese test in the same order
Show/Hide sections with changes/issues
- **`Description` section has changed**
```diff
@@ -1,3 +1,2 @@
-
It would teach us a lot about the filter method if we try to implement a version of it that behaves exactly like Array.prototype.filter(). It can use either a for loop or Array.prototype.forEach().
-
Note: A pure function is allowed to alter local variables defined within its scope, although, it's preferable to avoid that as well.
\ No newline at end of file
+
You might learn a lot about the filter method if you implement your own version of it. It is recommended you use a for loop or Array.prototype.forEach().
\ No newline at end of file
```
- **`Instructions` section has changed**
```diff
@@ -1,2 +1,2 @@
-
Write your own Array.prototype.myFilter(), which should behave exactly like Array.prototype.filter(). You may use a for loop or the Array.prototype.forEach() method.
\ No newline at end of file
+
Write your own Array.prototype.myFilter(), which should behave exactly like Array.prototype.filter(). You should not use the built-in filter method. The Array instance can be accessed in the myFilter method using this.
Show/Hide sections with changes/issues
- **`Instructions` section has changed**
```diff
@@ -1,3 +1,3 @@
Let's update the incrementer function to clearly declare its dependencies.
-
Write the incrementer function so it takes an argument, and then increases the value by one.
\ No newline at end of file
+
Write the incrementer function so it takes an argument, and then returns a result after increasing the value by one.
\ No newline at end of file
```
- **The following test(s) `text` do not match:**
**Instructions:** Make sure to also check that the English tests have not been reorderd.
**Test 1**
Version
Text
Old
```
Your function incrementer should not change the value of fixedValue.
```
New
```
Your function `incrementer` should not change the value of `fixedValue` (which is `4`).
```
**Test 2**
Version
Text
Old
```
Your incrementer function should take a parameter.
```
New
```
Your `incrementer` function should take an argument.
```
[ ] Use Higher-Order Functions map, filter, or reduce to Solve a Complex ProblemEdit Chinese | View English
Show/Hide sections with changes/issues
- **The following test(s) `text` do not match:**
**Instructions:** Make sure to also check that the English tests have not been reorderd.
**Test 2**
Version
Text
Old
```
for or while loops or forEach should not be used.
```
New
```
`for`, `while`, and `forEach` should not be used.
```
Show/Hide sections with changes/issues
- **Number of tests do not match - English: 5 | Chinese: 4**
**Instructions:** Add or delete the applicable tests. It is possible some tests have been rearranged, so make sure each English test has a corresponding Chinese test in the same order
Show/Hide sections with changes/issues
- **`Description` section has changed**
```diff
@@ -1,5 +1,4 @@
As you have seen from applying Array.prototype.map(), or simply map() earlier, the map method returns an array of the same length as the one it was called on. It also doesn't alter the original array, as long as its callback function doesn't.
In other words, map is a pure function, and its output depends solely on its inputs. Plus, it takes another function as its argument.
-
It would teach us a lot about map to try to implement a version of it that behaves exactly like the Array.prototype.map() with a for loop or Array.prototype.forEach().
-
Note: A pure function is allowed to alter local variables defined within its scope, although, it's preferable to avoid that as well.
\ No newline at end of file
+
You might learn a lot about the map method if you implement your own version of it. It is recommended you use a for loop or Array.prototype.forEach().
\ No newline at end of file
```
- **`Instructions` section has changed**
```diff
@@ -1,2 +1,2 @@
-
Write your own Array.prototype.myMap(), which should behave exactly like Array.prototype.map(). You may use a for loop or the forEach method.
\ No newline at end of file
+
Write your own Array.prototype.myMap(), which should behave exactly like Array.prototype.map(). You should not use the built-in map method. The Array instance can be accessed in the myMap method using this.
Show/Hide sections with changes/issues
- **`Description` section has changed**
```diff
@@ -1,5 +1,5 @@
So far, we have seen two distinct principles for functional programming:
-
1) Don't alter a variable or object - create new variables and objects and return them if need be from a function.
-
2) Declare function arguments - any computation inside a function depends only on the arguments, and not on any global object or variable.
+
1) Don't alter a variable or object - create new variables and objects and return them if need be from a function. Hint: using something like var newArr = arrVar, where arrVar is an array will simply create a reference to the existing variable and not a copy. So changing a value in newArr would change the value in arrVar.
+
2) Declare function parameters - any computation inside a function depends only on the arguments passed to the function, and not on any global object or variable.
Adding one to a number is not very exciting, but we can apply these principles when working with arrays or more complex objects.
\ No newline at end of file
```
- **`Instructions` section has changed**
```diff
@@ -1,2 +1,3 @@
-
Rewrite the code so the global array bookList is not changed inside either function. The add function should add the given bookName to the end of an array. The remove function should remove the given bookName from an array. Both functions should return an array, and any new parameters should be added before the bookName parameter.
\ No newline at end of file
+
Rewrite the code so the global array bookList is not changed inside either function. The add function should add the given bookName to the end of the array passed to it and return a new array (list). The remove function should remove the given bookName from the array passed to it.
Note: Both functions should return an array, and any new parameters should be added before the bookName parameter.
Show/Hide sections with changes/issues
- **Number of tests do not match - English: 4 | Chinese: 3**
**Instructions:** Add or delete the applicable tests. It is possible some tests have been rearranged, so make sure each English test has a corresponding Chinese test in the same order
Show/Hide sections with changes/issues
- **`Description` section has changed**
```diff
@@ -1,8 +1,7 @@
The const declaration has many use cases in modern JavaScript.
Some developers prefer to assign all their variables using const by default, unless they know they will need to reassign the value. Only in that case, they use let.
-
However, it is important to understand that objects (including arrays and functions) assigned to a variable using const are still mutable. Using the const declaration only prevents reassignment of the variable identifier.
"use strict";
-const s = [5, 6, 7];
+
However, it is important to understand that objects (including arrays and functions) assigned to a variable using const are still mutable. Using the const declaration only prevents reassignment of the variable identifier.
const s = [5, 6, 7];
s = [1, 2, 3]; // throws error, trying to assign a const
s[2] = 45; // works just as it would with an array declared with var or let
console.log(s); // returns [5, 6, 45]
```
- **`Instructions` section has changed**
```diff
@@ -1,2 +1,2 @@
-
An array is declared as const s = [5, 7, 2]. Change the array to [2, 5, 7] using various element assignment.
\ No newline at end of file
+
An array is declared as const s = [5, 7, 2]. Change the array to [2, 5, 7] using various element assignments.
Show/Hide sections with changes/issues
- **`Description` section has changed**
```diff
@@ -1,6 +1,5 @@
-
The keyword let is not the only new way to declare variables. In ES6, you can also declare variables using the const keyword.
const has all the awesome features that let has, with the added bonus that variables declared using const are read-only. They are a constant value, which means that once a variable is assigned with const, it cannot be reassigned.
"use strict";
-const FAV_PET = "Cats";
+
The keyword let is not the only new way to declare variables. In ES6, you can also declare variables using the const keyword.
const has all the awesome features that let has, with the added bonus that variables declared using const are read-only. They are a constant value, which means that once a variable is assigned with const, it cannot be reassigned.
As you can see, trying to reassign a variable declared with const will throw an error. You should always name variables you don't want to reassign using the const keyword. This helps when you accidentally attempt to reassign a variable that is meant to stay constant. A common practice when naming constants is to use all uppercase letters, with words separated by an underscore.
Show/Hide sections with changes/issues
- **`Description` section has changed**
```diff
@@ -14,5 +14,5 @@
When there is no function body, and only a return value, arrow function syntax allows you to omit the keyword return as well as the brackets surrounding the code. This helps simplify smaller functions into one-line statements:
const myFunc = () => "value";
-
This code will still return value by default.
+
This code will still return the string value by default.
\ No newline at end of file
```
- **`Instructions` section has changed**
```diff
@@ -1,2 +1,2 @@
-
Rewrite the function assigned to the variable magic which returns a new Date() to use arrow function syntax. Also make sure nothing is defined using the keyword var.
\ No newline at end of file
+
Rewrite the function assigned to the variable magic which returns a new Date() to use arrow function syntax. Also, make sure nothing is defined using the keyword var.
\ No newline at end of file
```
[ ] Use Destructuring Assignment to Assign Variables from Nested ObjectsEdit Chinese | View English
Show/Hide sections with changes/issues
- **Number of tests do not match - English: 4 | Chinese: 3**
**Instructions:** Add or delete the applicable tests. It is possible some tests have been rearranged, so make sure each English test has a corresponding Chinese test in the same order
Show/Hide sections with changes/issues
- **`Description` section has changed**
```diff
@@ -1,13 +1,15 @@
Just like a regular function, you can pass arguments into an arrow function.
// doubles input value and returns it
const doubler = (item) => item * 2;
+doubler(4); // returns 8
-
If an arrow function has a single argument, the parentheses enclosing the argument may be omitted.
-
// the same function, without the argument parentheses
+
If an arrow function has a single parameter, the parentheses enclosing the parameter may be omitted.
+
// the same function, without the parameter parentheses
const doubler = item => item * 2;
It is possible to pass more than one argument into an arrow function.
// multiplies the first input value by the second and returns it
const multiplier = (item, multi) => item * multi;
+multiplier(4, 2); // returns 8
\ No newline at end of file
```
- **The following test(s) `text` do not match:**
**Instructions:** Make sure to also check that the English tests have not been reorderd.
**Test 3**
Version
Text
Old
```
myConcat should be a function.
```
New
```
`myConcat` should be an arrow function with two parameters
```
[ ] Use Destructuring Assignment to Pass an Object as a Function's ParametersEdit Chinese | View English
Show/Hide sections with changes/issues
- **`Description` section has changed**
```diff
@@ -10,6 +10,5 @@
/* do something with these fields */
}
-
This removes some extra lines and makes our code look neat.
-This has the added benefit of not having to manipulate an entire object in a function — only the fields that are needed are copied inside the function.
+
When profileData is passed to the above function, the values are destructured from the function parameter for use within the function.
Show/Hide sections with changes/issues
- **`Description` section has changed**
```diff
@@ -34,8 +34,7 @@ console.log(printNumTwo());
// returns 3
As you can see, printNumTwo() prints 3 and not 2. This is because the value assigned to i was updated and the printNumTwo() returns the global i and not the value i had when the function was created in the for loop. The let keyword does not follow this behavior:
-
'use strict';
-let printNumTwo;
+
let printNumTwo;
for (let i = 0; i < 3; i++) {
if (i === 2) {
printNumTwo = function() {
```
Show/Hide sections with changes/issues
- **The following test(s) `text` do not match:**
**Instructions:** Make sure to also check that the English tests have not been reorderd.
**Test 1**
Version
Text
Old
```
resolve should be executed when the if condition is true.
```
New
```
`resolve` should be called with the expected string when the `if` condition is `true`.
```
**Test 2**
Version
Text
Old
```
reject should be executed when the if condition is false.
```
New
```
`reject` should be called with the expected string when the `if` condition is `false`.
```
Show/Hide sections with changes/issues
- **`Instructions` section has changed**
```diff
@@ -1,3 +1,9 @@
-
Use template literal syntax with backticks to display each entry of the result object's failure array. Each entry should be wrapped inside an li element with the class attribute text-warning, and listed within the resultDisplayArray.
-
Use an iterator method (any kind of loop) to get the desired output.
\ No newline at end of file
+
Use template literal syntax with backticks to create an array of list element (li) strings. Each list element's text should be one of the array elements from the failure property on the result object and have a class attribute with the value text-warning. The makeList function should return the array of list item strings.
+
Use an iterator method (any kind of loop) to get the desired output (shown below).
+
\ No newline at end of file
```
- **The following test(s) `text` do not match:**
**Instructions:** Make sure to also check that the English tests have not been reorderd.
**Test 1**
Version
Text
Old
```
resultDisplayArray should be an array containing result failure messages.
```
New
```
`failuresList` should be an array containing `result failure` messages.
```
**Test 2**
Version
Text
Old
```
resultDisplayArray should be equal to the specified output.
```
New
```
`failuresList` should be equal to the specified output.
```
Show/Hide sections with changes/issues
- **Number of tests do not match - English: 4 | Chinese: 3**
**Instructions:** Add or delete the applicable tests. It is possible some tests have been rearranged, so make sure each English test has a corresponding Chinese test in the same order
[ ] Use Destructuring Assignment with the Rest Parameter to Reassign Array ElementsEdit Chinese | View English
Variables a and b take the first and second values from the array. After that, because of rest parameter's presence, arr gets rest of the values in the form of an array.
-The rest element only works correctly as the last variable in the list. As in, you cannot use the rest parameter to catch a subarray that leaves out last element of the original array.
+
Variables a and b take the first and second values from the array. After that, because of the rest parameter's presence, arr gets the rest of the values in the form of an array.
+The rest element only works correctly as the last variable in the list. As in, you cannot use the rest parameter to catch a subarray that leaves out the last element of the original array.
\ No newline at end of file
```
- **Number of tests do not match - English: 4 | Chinese: 3**
**Instructions:** Add or delete the applicable tests. It is possible some tests have been rearranged, so make sure each English test has a corresponding Chinese test in the same order
Notice the syntax used to invoke the getter and setter. They do not even look like functions.
Getters and setters are important because they hide internal implementation details.
```
- **`Instructions` section has changed**
```diff
@@ -1,6 +1,6 @@
Use the class keyword to create a Thermostat class. The constructor accepts a Fahrenheit temperature.
-
Now create a getter and a setter in the class, to obtain the temperature in Celsius.
+
In the class, create a getter to obtain the temperature in Celsius and a setter to set the temperature in Celsius.
Remember that C = 5/9 * (F - 32) and F = C * 9.0 / 5 + 32, where F is the value of temperature in Fahrenheit, and C is the value of the same temperature in Celsius.
Note: When you implement this, you will track the temperature inside the class in one scale, either Fahrenheit or Celsius.
This is the power of a getter and a setter. You are creating an API for another user, who can get the correct result regardless of which one you track.
In other words, you are abstracting implementation details from the user.
\ No newline at end of file
```
- **Number of tests do not match - English: 7 | Chinese: 6**
**Instructions:** Add or delete the applicable tests. It is possible some tests have been rearranged, so make sure each English test has a corresponding Chinese test in the same order
Show/Hide sections with changes/issues
- **`Description` section has changed** ```diff @@ -1,5 +1,4 @@Given a positive integer
num
, return the sum of all odd Fibonacci numbers that are less than or equal tonum
.The first two numbers in the Fibonacci sequence are 1 and 1. Every additional number in the sequence is the sum of the two previous numbers. The first six numbers of the Fibonacci sequence are 1, 1, 2, 3, 5 and 8.
-For example,
-sumFibs(10)
should return10
because all odd Fibonacci numbers less than or equal to10
are 1, 1, 3, and 5.Remember to use Read-Search-Ask if you get stuck. Try to pair program. Write your own code.
For example,
\ No newline at end of file ```sumFibs(10)
should return10
because all odd Fibonacci numbers less than or equal to10
are 1, 1, 3, and 5.Show/Hide sections with changes/issues
- **`Description` section has changed** ```diff @@ -1,3 +1,2 @@You will be provided with an initial array (the first argument in the destroyer function), followed by one or more arguments. Remove all elements from the initial array that are of the same value as these arguments.
Note
-You have to use the
arguments
object.Remember to use Read-Search-Ask if you get stuck. Write your own code.
You will be provided with an initial array (the first argument in the destroyer function), followed by one or more arguments. Remove all elements from the initial array that are of the same value as these arguments.
Note
\ No newline at end of file ```You have to use the
arguments
object.Show/Hide sections with changes/issues
- **`Description` section has changed** ```diff @@ -4,5 +4,4 @@ itself. For example, 2 is a prime number because it is only divisible by 1 and 2 contrast, 4 is not prime since it is divisible by 1, 2 and 4.Rewrite
-sumPrimes
so it returns the sum of all prime numbers that are less than or equal to num.Remember to use Read-Search-Ask if you get stuck. Try to pair program. Write your own code.
\ No newline at end of file ```Show/Hide sections with changes/issues
- **`Description` section has changed** ```diff @@ -2,5 +2,4 @@Check if the predicate (second argument) is truthy on all elements of a collection (first argument).
In other words, you are given an array collection of objects. The predicate
pre
will be an object property and you need to returntrue
if its value istruthy
. Otherwise, returnfalse
.In JavaScript,
-truthy
values are values that translate totrue
when evaluated in a Boolean context.Remember, you can access object properties through either dot notation or
-[]
notation.Remember to use Read-Search-Ask if you get stuck. Try to pair program. Write your own code.
\ No newline at end of file +Remember, you can access object properties through either dot notation or
\ No newline at end of file ``` - **The following test(s) `text` do not match:** **Instructions:** Make sure to also check that the English tests have not been reorderd. **Test 4**[]
notation.truthCheck([{"name": "Pete", "onBoat": true}, {"name": "Repeat", "onBoat": true}, {"name": "FastFoward", "onBoat": null}], "onBoat")
should return false ```truthCheck([{"name": "Pete", "onBoat": true}, {"name": "Repeat", "onBoat": true, "alias": "Repete"}, {"name": "FastFoward", "onBoat": true}], "onBoat")
should return true ```Show/Hide sections with changes/issues
- **`Description` section has changed** ```diff @@ -1,5 +1,4 @@Find the smallest common multiple of the provided parameters that can be evenly divided by both, as well as by all sequential numbers in the range between these parameters.
The range will be an array of two numbers that will not necessarily be in numerical order.
-For example, if given 1 and 3, find the smallest common multiple of both 1 and 3 that is also evenly divisible by all numbers between 1 and 3. The answer here would be 6.
-Remember to use Read-Search-Ask if you get stuck. Try to pair program. Write your own code.
For example, if given 1 and 3, find the smallest common multiple of both 1 and 3 that is also evenly divisible by all numbers between 1 and 3. The answer here would be 6.
\ No newline at end of file ```Show/Hide sections with changes/issues
- **`Description` section has changed** ```diff @@ -1,3 +1,2 @@Convert the characters
-&
,<
,>
,"
(double quote), and'
(apostrophe), in a string to their corresponding HTML entities.Remember to use Read-Search-Ask if you get stuck. Try to pair program. Write your own code.
Convert the characters
\ No newline at end of file ``` - **The following test(s) `text` do not match:** **Instructions:** Make sure to also check that the English tests have not been reorderd. **Test 1**&
,<
,>
,"
(double quote), and'
(apostrophe), in a string to their corresponding HTML entities.convertHTML("Dolce & Gabbana")
should returnDolce & Gabbana
. ```convertHTML("Hamburgers < Pizza < Tacos")
should returnHamburgers < Pizza < Tacos
. ```convertHTML("Sixty > twelve")
should returnSixty > twelve
. ```convertHTML('Stuff in "quotation marks"')
should returnStuff in "quotation marks"
. ```convertHTML("Schindler's List")
should returnSchindler's List
. ```convertHTML("<>")
should return<>
. ```convertHTML("abc")
should returnabc
. ```Show/Hide sections with changes/issues
- **`Description` section has changed** ```diff @@ -1,3 +1,2 @@Flatten a nested array. You must account for varying levels of nesting.
-Remember to use Read-Search-Ask if you get stuck. Try to pair program. Write your own code.
Flatten a nested array. You must account for varying levels of nesting.
\ No newline at end of file ``` - **Number of tests do not match - English: 5 | Chinese: 4** **Instructions:** Add or delete the applicable tests. It is possible some tests have been rearranged, so make sure each English test has a corresponding Chinese test in the same orderShow/Hide sections with changes/issues
- **`Description` section has changed** ```diff @@ -2,5 +2,4 @@Perform a search and replace on the sentence using the arguments provided and return the new sentence.
First argument is the sentence to perform the search and replace on.
Second argument is the word that you will be replacing (before).
-Third argument is what you will be replacing the second argument with (after).
Note
-Preserve the case of the first character in the original word when you are replacing it. For example if you mean to replace the word "Book" with the word "dog", it should be replaced as "Dog"
Remember to use Read-Search-Ask if you get stuck. Try to pair program. Write your own code.
\ No newline at end of file +Third argument is what you will be replacing the second argument with (after).
Note
\ No newline at end of file ``` - **Number of tests do not match - English: 6 | Chinese: 5** **Instructions:** Add or delete the applicable tests. It is possible some tests have been rearranged, so make sure each English test has a corresponding Chinese test in the same orderPreserve the case of the first character in the original word when you are replacing it. For example if you mean to replace the word "Book" with the word "dog", it should be replaced as "Dog"
Show/Hide sections with changes/issues
- **`Description` section has changed** ```diff @@ -2,5 +2,4 @@Write a function that takes two or more arrays and returns a new array of unique values in the order of the original provided arrays.
In other words, all values present from all arrays should be included in their original order, but with no duplicates in the final array.
The unique numbers should be sorted by their original order, but the final array should not be sorted in numerical order.
-Check the assertion tests for examples.
-Remember to use Read-Search-Ask if you get stuck. Try to pair program. Write your own code.
\ No newline at end of file +Check the assertion tests for examples.
\ No newline at end of file ```Show/Hide sections with changes/issues
- **`Description` section has changed** ```diff @@ -1,4 +1,3 @@Given the array
-arr
, iterate through and remove each element starting from the first element (the 0 index) until the functionfunc
returnstrue
when the iterated element is passed through it.Then return the rest of the array once the condition is satisfied, otherwise,
-arr
should be returned as an empty array.Remember to use Read-Search-Ask if you get stuck. Try to pair program. Write your own code.
Then return the rest of the array once the condition is satisfied, otherwise,
\ No newline at end of file ```arr
should be returned as an empty array.Show/Hide sections with changes/issues
- **`Description` section has changed** ```diff @@ -3,5 +3,4 @@For example,
addTogether(2, 3)
should return5
, andaddTogether(2)
should return a function.Calling this returned function with a single argument will then return the sum:
var sumTwoAnd = addTogether(2);
-sumTwoAnd(3)
returns5
.If either argument isn't a valid number, return undefined.
-Remember to use Read-Search-Ask if you get stuck. Try to pair program. Write your own code.
\ No newline at end of file +If either argument isn't a valid number, return undefined.
\ No newline at end of file ``` - **Number of tests do not match - English: 6 | Chinese: 5** **Instructions:** Add or delete the applicable tests. It is possible some tests have been rearranged, so make sure each English test has a corresponding Chinese test in the same orderShow/Hide sections with changes/issues
- **`Description` section has changed** ```diff @@ -1,4 +1,3 @@Return an English translated sentence of the passed binary string.
-The binary string will be space separated.
-Remember to use Read-Search-Ask if you get stuck. Try to pair program. Write your own code.
The binary string will be space separated.
\ No newline at end of file ```Show/Hide sections with changes/issues
- **`Description` section has changed** ```diff @@ -1,6 +1,4 @@Translate the provided string to pig latin.
Pig Latin takes the first consonant (or consonant cluster) of an English word, moves it to the end of the word and suffixes an "ay".
-If a word begins with a vowel you just add "way" to the end.
-If a word does not contain a vowel, just add "ay" to the end.
-Input strings are guaranteed to be English words in all lowercase.
-Remember to use Read-Search-Ask if you get stuck. Try to pair program. Write your own code.
Pig Latin is a way of altering English Words. The rules are as follows:
+- If a word begins with a consonant, take the first consonant or consonant cluster, move it to the end of the word, and add "ay" to it.
+- If a word begins with a vowel, just add "way" at the end.
\ No newline at end of file ``` - **`Instructions` section has changed** ```diff @@ -0,0 +1,2 @@ +Translate the provided string to Pig Latin. Input strings are guaranteed to be English words in all lowercase.
Show/Hide sections with changes/issues
- **`Description` section has changed** ```diff @@ -1,3 +1,2 @@Compare two arrays and return a new array with any items only found in one of the two given arrays, but not both. In other words, return the symmetric difference of the two arrays.
-Remember to use Read-Search-Ask if you get stuck. Try to pair program. Write your own code.
Note
You can return the array with its elements in any order.
Compare two arrays and return a new array with any items only found in one of the two given arrays, but not both. In other words, return the symmetric difference of the two arrays.
Note
\ No newline at end of file ```You can return the array with its elements in any order.
Show/Hide sections with changes/issues
- **`Description` section has changed** ```diff @@ -1,3 +1,2 @@Convert a string to spinal case. Spinal case is all-lowercase-words-joined-by-dashes.
-Remember to use Read-Search-Ask if you get stuck. Try to pair program. Write your own code.
Convert a string to spinal case. Spinal case is all-lowercase-words-joined-by-dashes.
\ No newline at end of file ```Show/Hide sections with changes/issues
- **`Description` section has changed** ```diff @@ -3,5 +3,4 @@The array will contain objects in the format
{name: 'name', avgAlt: avgAlt}
.You can read about orbital periods on Wikipedia.
The values should be rounded to the nearest whole number. The body being orbited is Earth.
-The radius of the earth is 6367.4447 kilometers, and the GM value of earth is 398600.4418 km3s-2.
-Remember to use Read-Search-Ask if you get stuck. Try to pair program. Write your own code.
\ No newline at end of file +The radius of the earth is 6367.4447 kilometers, and the GM value of earth is 398600.4418 km3s-2.
\ No newline at end of file ```Show/Hide sections with changes/issues
- **`Description` section has changed** ```diff @@ -2,5 +2,4 @@The DNA strand is missing the pairing element. Take each character, get its pair, and return the results as a 2d array.
Base pairs are a pair of AT and CG. Match the missing element to the provided character.
Return the provided character as the first element in each array.
For example, for the input GCG, return [["G", "C"], ["C","G"],["G", "C"]]
-The character and its pair are paired up in an array, and all the arrays are grouped into one encapsulating array.
-Remember to use Read-Search-Ask if you get stuck. Try to pair program. Write your own code.
\ No newline at end of file +The character and its pair are paired up in an array, and all the arrays are grouped into one encapsulating array.
\ No newline at end of file ```Show/Hide sections with changes/issues
- **`Description` section has changed** ```diff @@ -1,4 +1,3 @@Find the missing letter in the passed letter range and return it.
-If all letters are present in the range, return undefined.
-Remember to use Read-Search-Ask if you get stuck. Try to pair program. Write your own code.
If all letters are present in the range, return undefined.
\ No newline at end of file ```Show/Hide sections with changes/issues
- **`Description` section has changed** ```diff @@ -8,6 +8,5 @@ setFullName(firstAndLast)Run the tests to see the expected output for each method. The methods that take an argument must accept only one argument and it has to be a string. -These methods must be the only available means of interacting with the object. -Remember to use Read-Search-Ask if you get stuck. Try to pair program. Write your own code.
+These methods must be the only available means of interacting with the object. \ No newline at end of file ```Show/Hide sections with changes/issues
- **`Description` section has changed** ```diff @@ -1,4 +1,3 @@We'll pass you an array of two numbers. Return the sum of those two numbers plus the sum of all the numbers between them. The lowest number will not always come first.
For example,
-sumAll([4,1])
should return10
because sum of all the numbers between 1 and 4 (both inclusive) is10
.Remember to use Read-Search-Ask if you get stuck. Try to pair program. Write your own code.
Show/Hide sections with changes/issues
- **`Description` section has changed** ```diff @@ -1,4 +1,3 @@Make a function that looks through an array of objects (first argument) and returns an array of all objects that have matching name and value pairs (second argument). Each name and value pair of the source object has to be present in the object from the collection if it is to be included in the returned array.
-For example, if the first argument is
-[{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }]
, and the second argument is{ last: "Capulet" }
, then you must return the third object from the array (the first argument), because it contains the name and its value, that was passed on as the second argument.Remember to use Read-Search-Ask if you get stuck. Write your own code.
For example, if the first argument is
\ No newline at end of file ```[{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }]
, and the second argument is{ last: "Capulet" }
, then you must return the third object from the array (the first argument), because it contains the name and its value, that was passed on as the second argument.Show/Hide sections with changes/issues
- **`Description` section has changed** ```diff @@ -1,10 +1,15 @@So far, you have only been checking if a pattern exists or not within a string. You can also extract the actual matches you found with the
-.match()
method.To use the
.match()
method, apply the method on a string and pass in the regex inside the parentheses. Here's an example:Show/Hide sections with changes/issues
- **Number of tests do not match - English: 3 | Chinese: 1** **Instructions:** Add or delete the applicable tests. It is possible some tests have been rearranged, so make sure each English test has a corresponding Chinese test in the same orderShow/Hide sections with changes/issues
- **`Instructions` section has changed** ```diff @@ -1,2 +1,2 @@Write a regex so that it will search for the string
"good"
. Then update thereplaceText
variable to replace"good"
with"okey-dokey"
.Write a regex
\ No newline at end of file ``` - **Number of tests do not match - English: 5 | Chinese: 3** **Instructions:** Add or delete the applicable tests. It is possible some tests have been rearranged, so make sure each English test has a corresponding Chinese test in the same orderfixRegex
using three capture groups that will search for each word in the string "one two three". Then update thereplaceText
variable to replace "one two three" with the string "three two one" and assign the result to theresult
variable. Make sure you are utilizing capture groups in the replacement string using the dollar sign ($
) syntax.Show/Hide sections with changes/issues
- **`Description` section has changed** ```diff @@ -2,7 +2,7 @@Sometimes we want to check for groups of characters using a Regular Expression and to achieve that we use parentheses
()
.If you want to find either
Penguin
orPumpkin
in a string, you can use the following Regular Expression:/P(engu|umpk)in/g
Then check whether the desired string groups are in the test string by using the
``` - **Number of tests do not match - English: 6 | Chinese: 5** **Instructions:** Add or delete the applicable tests. It is possible some tests have been rearranged, so make sure each English test has a corresponding Chinese test in the same ordertest()
method.Show/Hide sections with changes/issues
- **`Description` section has changed** ```diff @@ -2,6 +2,6 @@Usernames are used everywhere on the internet. They are what give users a unique identity on their favorite sites.
You need to check all the usernames in a database. Here are some simple rules that users have to follow when creating their username.
1) Usernames can only use alpha-numeric characters.
-2) The only numbers in the username have to be at the end. There can be zero or more of them at the end.
+2) The only numbers in the username have to be at the end. There can be zero or more of them at the end. Username cannot start with the number.
3) Username letters can be lowercase and uppercase.
4) Usernames have to be at least two characters long. A two-character username can only use alphabet letters as characters.
\ No newline at end of file ``` - **Number of tests do not match - English: 12 | Chinese: 11** **Instructions:** Add or delete the applicable tests. It is possible some tests have been rearranged, so make sure each English test has a corresponding Chinese test in the same orderShow/Hide sections with changes/issues
- **The following test(s) `text` do not match:** **Instructions:** Make sure to also check that the English tests have not been reorderd. **Test 2**\S/code> to match all non-whitespace characters. ```
Show/Hide sections with changes/issues
- **Number of tests do not match - English: 9 | Chinese: 10** **Instructions:** Add or delete the applicable tests. It is possible some tests have been rearranged, so make sure each English test has a corresponding Chinese test in the same orderShow/Hide sections with changes/issues
- **`Instructions` section has changed** ```diff @@ -1,2 +1,2 @@Write a regex and use the appropriate string methods to remove whitespace at the beginning and end of strings.
Note
The
.trim()
method would work here, but you'll need to complete this challenge using regular expressions.Write a regex and use the appropriate string methods to remove whitespace at the beginning and end of strings.
Note: The
\ No newline at end of file ``` - **The following test(s) `text` do not match:** **Instructions:** Make sure to also check that the English tests have not been reorderd. **Test 2**String.prototype.trim()
method would work here, but you'll need to complete this challenge using regular expressions..trim()
method. ```Show/Hide sections with changes/issues
- **`Description` section has changed** ```diff @@ -1,7 +1,8 @@You may have noticed that some freeCodeCamp JavaScript challenges include their own console. This console behaves a little differently than the browser console you used in the last challenge.
The following challenge is meant to highlight the main difference between the freeCodeCamp console and your browser console.
-When you run ordinary JavaScript, the browsers console will display your
-console.log()
statements the exact number of times you requested.The freeCodeCamp console will print your
-console.log()
statements for each test of that challenge, as well as one more time for any function calls that you have in your code.This lends itself to some interesting behavior and might trip you up in the beginning, because a logged value that you expect to see only once may print out many more times.
-If you would like to see only your single output and not have to worry about running through the test cycles, you can use
console.clear()
and check the browsers console.When you run ordinary JavaScript, the browser's console will display your
+console.log()
statements the exact number of times it is called.The freeCodeCamp console will print your
+console.log()
statements a short time after the editor detects a change in the script, as well as during testing.The freeCodeCamp console is cleared before the tests are run and, to avoid spam, only prints the logs during the first test (see the note below for exceptions).
+If you would like to see every log for every test, run the tests, and open the browser console. If you prefer to use the browser console, and want it to mimic the freeCodeCamp console, place
console.clear()
before any otherconsole
calls, to clear the browser console.Note:
+ \ No newline at end of file ``` - **`Instructions` section has changed** ```diff @@ -1,2 +1,2 @@console.log
s inside functions are printed to the freeCodeCamp console whenever those functions are called, this can help debugging functions that are called during testing.First, use
console.clear()
to clear the browser console. After that, useconsole.log
to log theoutput
variable.First, use
\ No newline at end of file ```console.log
to log theoutput
variable. Then, useconsole.clear
to clear the browser console.Show/Hide sections with changes/issues
- **`Description` section has changed** ```diff @@ -2,7 +2,7 @@A for loop can also count backwards, so long as we can define the right conditions.
In order to count backwards by twos, we'll need to change our
initialization
,condition
, andfinal-expression
.We'll start at
```i = 10
and loop whilei > 0
. We'll decrementi
by 2 each loop withi -= 2
.Show/Hide sections with changes/issues
- **`Description` section has changed** ```diff @@ -1,6 +1,6 @@The conditional operator, also called the ternary operator, can be used as a one line if-else expression.
-The syntax is:
+condition ? statement-if-true : statement-if-false;
The syntax is:
condition ? expression-if-true : expression-if-false;
The following function uses an if-else statement to check a condition:
Show/Hide sections with changes/issues
- **`Description` section has changed** ```diff @@ -1,6 +1,6 @@In computer science, data is anything that is meaningful to the computer. JavaScript provides seven different data types which are
-undefined
,null
,boolean
,string
,symbol
,number
, andobject
.For example, computers distinguish between numbers, such as the number
12
, andstrings
, such as"12"
,"dog"
, or"123 cats"
, which are collections of characters. Computers can perform mathematical operations on a number, but not on a string.Variables allow computers to store and manipulate data in a dynamic fashion. They do this by using a "label" to point to the data rather than using the data itself. Any of the seven data types may be stored in a variable.
+Variables
are similar to the x and y variables you use in mathematics, which means they're a simple name to represent the data we want to refer to. Computervariables
differ from mathematical variables in that they can store different values at different times.In computer science, data is anything that is meaningful to the computer. JavaScript provides eight different data types which are
+undefined
,null
,boolean
,string
,symbol
,bigint
,number
, andobject
.For example, computers distinguish between numbers, such as the number
12
, andstrings
, such as"12"
,"dog"
, or"123 cats"
, which are collections of characters. Computers can perform mathematical operations on a number, but not on a string.Variables allow computers to store and manipulate data in a dynamic fashion. They do this by using a "label" to point to the data rather than using the data itself. Any of the eight data types may be stored in a variable.
Variables
are similar to the x and y variables you use in mathematics, which means they're a simple name to represent the data we want to refer to. Computervariables
differ from mathematical variables in that they can store different values at different times.We tell JavaScript to create or declare a variable by putting the keyword
var
in front of it, like so:creates a
-
\ No newline at end of file
+
variable
calledourName
. In JavaScript we end statements with semicolons. ``` - **`Instructions` section has changed** ```diff @@ -1,2 +1,2 @@Use the
var
keyword to create a variable calledmyName
.Hint
Look at the
ourName
example if you get stuck.Use the
var
keyword to create a variable calledmyName
.Hint
Look at the
ourName
example above if you get stuck.Show/Hide sections with changes/issues
- **`Description` section has changed** ```diff @@ -1,16 +1,3 @@In a previous challenge, 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 base case. 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 recursive call which executes the original function with different arguments. If the function is written correctly, eventually the base case will be reached.
-For example, say you want to write a recursive function that returns an array containing the numbers 1 through n. This function will need to accept an argument
- -n
representing the final number. Then it will need to call itself with progressively smaller values ofn
until it reaches 1. You could write the function as follows:At first this is 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 wheren
is pushed into the array,count(n - 1)
has already been evaluated and returned[1, 2, ..., n - 1]
.Continuing from the previous challenge, we provide you another opportunity to create a recursive function to solve a problem.
rangeOfNumbers(4, 4)
should should return[4]
. ```Show/Hide sections with changes/issues
- **`Description` section has changed** ```diff @@ -3,4 +3,8 @@Note
+Watch out for spaces. Concatenation does not add spaces between concatenated strings, so you'll need to add them yourself.
Example:
+ \ No newline at end of file ```Show/Hide sections with changes/issues
- **`Description` section has changed** ```diff @@ -1,5 +1,5 @@You may recall from Comparison with the Equality Operator that all comparison operators return a boolean
+true
orfalse
value.You may recall from Comparison with the Equality Operator that all comparison operators return a boolean
true
orfalse
value.Sometimes people use an if/else statement to do a comparison, like this:
Show/Hide sections with changes/issues
- **The following test(s) `text` do not match:** **Instructions:** Make sure to also check that the English tests have not been reorderd. **Test 1**"Kristian", "lastName"
should return"Vos"
```"Sherlock", "likes"
should return["Intriguing Cases", "Violin"]
```"Harry","likes"
should return an array ```"Bob", "number"
should return "No such contact" ```"Bob", "potato"
should return "No such contact" ```"Akira", "address"
should return "No such property" ```Show/Hide sections with changes/issues
- **`Instructions` section has changed** ```diff @@ -1,2 +1,2 @@Use the
playerNumber
variable to look up player16
intestObj
using bracket notation. Then assign that name to theplayer
variable.Set the
\ No newline at end of file ```playerNumber
variable to16
. Then, use the variable to look up the player's name and assign it toplayer
.Show/Hide sections with changes/issues
- **The following test(s) `text` do not match:** **Instructions:** Make sure to also check that the English tests have not been reorderd. **Test 2**Math.random
to generate a random number. ```Show/Hide sections with changes/issues
- **`Description` section has changed** ```diff @@ -1,4 +1,4 @@Random numbers are useful for creating random behavior.
JavaScript has a
-Math.random()
function that generates a random decimal number between0
(inclusive) and not quite up to1
(exclusive). ThusMath.random()
can return a0
but never quite return a1
Note
Like Storing Values with the Equal Operator, all function calls will be resolved before the
return
executes, so we canreturn
the value of theMath.random()
function.Note
\ No newline at end of file ```Like Storing Values with the Equal Operator, all function calls will be resolved before the
return
executes, so we canreturn
the value of theMath.random()
function.Show/Hide sections with changes/issues
- **`Instructions` section has changed** ```diff @@ -1,2 +1,2 @@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"Write chained
if
/else if
statements to fulfill the following conditions:
\ No newline at end of file ```num < 5
- return "Tiny"num < 10
- return "Small"num < 15
- return "Medium"num < 20
- return "Large"num >= 20
- return "Huge"Show/Hide sections with changes/issues
- **`Description` section has changed** ```diff @@ -1,3 +1,5 @@You can also nest arrays within other arrays, like this:
[["Bulls", 23], ["White Sox", 45]]
. This is also called a multi-dimensional array. -You can also nest arrays within other arrays, like below:
+This is also called a multi-dimensional array.
+ \ No newline at end of file ```Show/Hide sections with changes/issues
- **`Description` section has changed** ```diff @@ -1,2 +1,8 @@Not only can you
shift
elements off of the beginning of an array, you can alsounshift
elements to the beginning of an array i.e. add elements in front of the array..unshift()
works exactly like.push()
, but instead of adding the element at the end of the array,unshift()
adds the element at the beginning of the array.Not only can you
shift
elements off of the beginning of an array, you can alsounshift
elements to the beginning of an array i.e. add elements in front of the array..unshift()
works exactly like.push()
, but instead of adding the element at the end of the array,unshift()
adds the element at the beginning of the array.Example:
+ + \ No newline at end of file ```Show/Hide sections with changes/issues
- **`Description` section has changed** ```diff @@ -1,8 +1,8 @@In JavaScript, you can store a value in a variable with the assignment operator.
+myVariable = 5;
In JavaScript, you can store a value in a variable with the assignment operator (
=
).myVariable = 5;
This assigns the
-Number
value5
tomyVariable
.Assignment always goes from right to left. Everything to the right of the
=
operator is resolved before the value is assigned to the variable to the left of the operator.Assign the value
-7
to variablea
.Assign the contents of
a
to variableb
.Assign the value
\ No newline at end of file ``` - **Number of tests do not match - English: 2 | Chinese: 4** **Instructions:** Add or delete the applicable tests. It is possible some tests have been rearranged, so make sure each English test has a corresponding Chinese test in the same order7
to variablea
.Show/Hide sections with changes/issues
- **`Description` section has changed** ```diff @@ -1,5 +1,5 @@Quotes are not the only characters that can be escaped inside a string. There are two reasons to use escaping characters:
- To allow you to use characters you may not otherwise be able to type out, such as a carriage returns.
- To allow you to represent multiple quotes in a string without JavaScript misinterpreting what you mean.
We learned this in the previous challenge.\'
\"
\
+Code Output single quote double quote backslash
newline
carriage return
tab
word boundary
form feed
- [ ] Global Scope and Functions Edit Chinese | View English
-
\ No newline at end of file
```
- [ ] Build JavaScript Objects Edit Chinese | View English
\ No newline at end of file
+
- [ ] Record Collection Edit Chinese | View English
-
\ No newline at end of file
+
- [ ] Use Multiple Conditional (Ternary) Operators Edit Chinese | View English
-Quotes are not the only characters that can be escaped inside a string. There are two reasons to use escaping characters:
- To allow you to use characters you may not otherwise be able to type out, such as a carriage return.
- To allow you to represent multiple quotes in a string without JavaScript misinterpreting what you mean.
We learned this in the previous challenge.\'
\"
\
Note that the backslash itself must be escaped in order to display as a backslash.
\ No newline at end of file ```Show/Hide sections with changes/issues
- **`Instructions` section has changed** ```diff @@ -1,3 +1,3 @@Using
+var
, declare aglobal
variablemyGlobal
outside of any function. Initialize it with a value of10
.Using
var
, declare a global variable namedmyGlobal
outside of any function. Initialize it with a value of10
.Inside function
fun1
, assign5
tooopsGlobal
without using thevar
keyword.Show/Hide sections with changes/issues
- **`Instructions` section has changed** ```diff @@ -1,3 +1,3 @@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
"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
\ No newline at end of file ```"name"
is a string,"legs"
and"tails"
are numbers, and"friends"
is an array.Show/Hide sections with changes/issues
- **`Description` section has changed** ```diff @@ -1,11 +1,12 @@You are given a JSON object representing a part of your musical album collection. Each album has several properties and a unique id number as its key. Not all albums have complete information.
-Write a function which takes an album's
-id
(like2548
), a propertyprop
(like"artist"
or"tracks"
), and avalue
(like"Addicted to Love"
) to modify the data in this collection.If
-prop
isn't"tracks"
andvalue
isn't empty (""
), update or set thevalue
for that record album's property.Your function must always return the entire collection object.
-There are several rules for handling incomplete data:
-If
-prop
is"tracks"
but the album doesn't have a"tracks"
property, create an empty array before adding the new value to the album's corresponding property.If
-prop
is"tracks"
andvalue
isn't empty (""
), push thevalue
onto the end of the album's existingtracks
array.If
value
is empty (""
), delete the givenprop
property from the album.Hints
-Use
bracket notation
when accessing object properties with variables.Push is an array method you can read about on Mozilla Developer Network.
-You may refer back to Manipulating Complex Objects Introducing JavaScript Object Notation (JSON) for a refresher.
You are given a JSON object representing a part of your musical album collection. Each album has a unique id number as its key and several other properties. Not all albums have complete information.
+You start with an
+updateRecords
function that takes an object likecollection
, anid
, aprop
(likeartist
ortracks
), and avalue
. Complete the function using the rules below to modify the object passed to the function.+- Your function must always return the entire object.
+- If
+- If
+- If
+- If
+
+prop
isn'ttracks
andvalue
isn't an empty string, update or set that album'sprop
tovalue
.prop
istracks
but the album doesn't have atracks
property, create an empty array and addvalue
to it.prop
istracks
andvalue
isn't an empty string, addvalue
to the end of the album's existingtracks
array.value
is an empty string, delete the givenprop
property from the album.Note: A copy of the
+ \ No newline at end of file ``` - **Number of tests do not match - English: 7 | Chinese: 8** **Instructions:** Add or delete the applicable tests. It is possible some tests have been rearranged, so make sure each English test has a corresponding Chinese test in the same ordercollection
object is used for the tests.Show/Hide sections with changes/issues
- **`Description` section has changed** ```diff @@ -19,7 +19,7 @@ : "b is greater"; }However, this should be used with care as using multiple conditional operators without proper indentation may make your code hard to read. For example:
+It is considered best practice to format multiple conditional operators such that each condition is on a separate line, as shown above. Using multiple conditional operators without proper indentation may make your code hard to read. For example:
-Note
+There shouldn't be any spaces between the array name and the square brackets, like
array [0][0]
and even thisarray [0][0]
is not allowed. Although JavaScript is able to process this correctly, this may confuse other programmers reading your code.Note
\ No newline at end of file ```There shouldn't be any spaces between the array name and the square brackets, like
array [0][0]
and even thisarray [0] [0]
is not allowed. Although JavaScript is able to process this correctly, this may confuse other programmers reading your code.Show/Hide sections with changes/issues
- **`Description` section has changed** ```diff @@ -1,3 +1,22 @@We can also delete properties from objects like this:
+delete ourDog.bark;
Example:
+ +After the last line shown above,
+ourDog
looks like:Show/Hide sections with changes/issues
- **`Description` section has changed** ```diff @@ -1,6 +1,6 @@There are many comparison operators in JavaScript. All of these operators return a boolean
-true
orfalse
value.The most basic operator is the equality operator
==
. The equality operator compares two values and returnstrue
if they're equivalent orfalse
if they are not. Note that equality is different from assignment (=
), which assigns the value at the right of the operator to a variable in the left.Show/Hide sections with changes/issues
- **`Description` section has changed** ```diff @@ -1,4 +1,8 @@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
+var firstName = "Charles"
string by usingfirstName[firstName.length - 3]
Example:
+Use bracket notation to find the second-to-last character in the
lastName
string.Hint
Try looking at the
thirdToLastLetterOfFirstName
variable declaration if you get stuck.Use bracket notation to find the second-to-last character in the
lastName
string.Hint: Try looking at the example above if you get stuck.
\ No newline at end of file ```Show/Hide sections with changes/issues
- **`Description` section has changed** ```diff @@ -1,3 +1,8 @@
-pop()
always removes the last element of an array. What if you want to remove the first?That's where
.shift()
comes in. It works just like.pop()
, except it removes the first element instead of the last.That's where
.shift()
comes in. It works just like.pop()
, except it removes the first element instead of the last.Example:
+ + \ No newline at end of file ```Show/Hide sections with changes/issues
- **`Description` section has changed** ```diff @@ -1,3 +1,7 @@You can also use bracket notation to get the character at other positions within a string.
-Remember that computers start counting at
0
, so the first character is actually the zeroth character.Remember that computers start counting at
0
, so the first character is actually the zeroth character.Example:
+ + \ No newline at end of file ``` - **`Instructions` section has changed** ```diff @@ -1,2 +1,2 @@Let's try to set
thirdLetterOfLastName
to equal the third letter of thelastName
variable using bracket notation.Hint
Try looking at the
secondLetterOfFirstName
variable declaration if you get stuck.Let's try to set
thirdLetterOfLastName
to equal the third letter of thelastName
variable using bracket notation.Hint: Try looking at the example above if you get stuck.
\ No newline at end of file ```Show/Hide sections with changes/issues
- **`Description` section has changed** ```diff @@ -1,5 +1,5 @@Instead of generating a random number between zero and a given number like we did before, we can generate a random number that falls within a range of two specific numbers.
+Instead of generating a random whole number between zero and a given number like we did before, we can generate a random whole number that falls within a range of two specific numbers.
To do this, we'll define a minimum number
min
and a maximum numbermax
.Here's the formula we'll use. Take a moment to read it and try to understand what this code is doing:
Math.floor(Math.random() * (max - min + 1)) + min
Create a function called
randomRange
that takes a rangemyMin
andmyMax
and returns a random number that's greater than or equal tomyMin
, and is less than or equal tomyMax
, inclusive.Create a function called
\ No newline at end of file ```randomRange
that takes a rangemyMin
andmyMax
and returns a random whole number that's greater than or equal tomyMin
, and is less than or equal tomyMax
, inclusive.Show/Hide sections with changes/issues
- **`Instructions` section has changed** ```diff @@ -1,2 +1,2 @@Modify the function
abTest
so that ifa
orb
are less than0
the function will immediately exit with a value ofundefined
.Hint
Remember that
undefined
is a keyword, not a string.Modify the function
abTest
so that ifa
orb
are less than0
the function will immediately exit with a value ofundefined
.Hint
\ No newline at end of file ``` - **Number of tests do not match - English: 7 | Chinese: 6** **Instructions:** Add or delete the applicable tests. It is possible some tests have been rearranged, so make sure each English test has a corresponding Chinese test in the same orderRemember that
undefined
is a keyword, not a string.Show/Hide sections with changes/issues
- **`Description` section has changed** ```diff @@ -1,2 +1,7 @@We can also use the
+=
operator to concatenate 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.
We can also use the
+=
operator to concatenate 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.
Example:
+ + \ No newline at end of file ```Show/Hide sections with changes/issues
- **`Description` section has changed** ```diff @@ -1,6 +1,11 @@An easy way to append data to the end of an array is via the
push()
function..push()
takes one or more parameters and "pushes" them onto the end of the array.Show/Hide sections with changes/issues
- **`Description` section has changed** ```diff @@ -1,5 +1,5 @@A common task in JavaScript is to iterate through the contents of an array. One way to do that is with a
for
loop. This code will output each element of the arrayarr
to the console:Show/Hide sections with changes/issues
- **`Description` section has changed** ```diff @@ -1,4 +1,4 @@If you'll recall from our discussion of Storing Values with the Assignment Operator, everything to the right of the equal sign is resolved before the value is assigned. This means we can take the return value of a function and assign it to a variable.
+If you'll recall from our discussion of Storing Values with the Assignment Operator, everything to the right of the equal sign is resolved before the value is assigned. This means we can take the return value of a function and assign it to a variable.
Assume we have pre-defined a function
sum
which adds two numbers together, then:ourSum = sum(5, 12);
will call
sum
function, which returns a value of17
and assigns it toourSum
variable.Show/Hide sections with changes/issues
- **`Description` section has changed** ```diff @@ -2,4 +2,14 @@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 toourDog
:ourDog.bark = "bow-wow";
or
-ourDog["bark"] = "bow-wow";
Now when we evaluate
\ No newline at end of file +ourDog.bark
, we'll get his bark, "bow-wow".Now when we evaluate
ourDog.bark
, we'll get his bark, "bow-wow".Example:
+ + \ No newline at end of file ```Show/Hide sections with changes/issues
- **`Description` section has changed** ```diff @@ -1,4 +1,8 @@Bracket notation 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 Zero-based 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 usingfirstName[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 usingfirstName[0]
.Example:
+ + \ No newline at end of file ``` - **`Instructions` section has changed** ```diff @@ -1,2 +1,2 @@Use bracket notation to find the first character in the
lastName
variable and assign it tofirstLetterOfLastName
.Hint
Try looking at the
firstLetterOfFirstName
variable declaration if you get stuck.Use bracket notation to find the first character in the
lastName
variable and assign it tofirstLetterOfLastName
.Hint: Try looking at the example above if you get stuck.
\ No newline at end of file ```Show/Hide sections with changes/issues
- **`Instructions` section has changed** ```diff @@ -1,2 +1,2 @@Modify the function
checkObj
to testmyObj
forcheckProp
. If the property is found, return that property's value. If not, return"Not Found"
.Modify the function
\ No newline at end of file ``` - **Number of tests do not match - English: 6 | Chinese: 3** **Instructions:** Add or delete the applicable tests. It is possible some tests have been rearranged, so make sure each English test has a corresponding Chinese test in the same ordercheckObj
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"
.Show/Hide sections with changes/issues
- **`Instructions` section has changed** ```diff @@ -1,2 +1,4 @@Declare a local variable
myVar
insidemyLocalScope
. Run the tests and then follow the instructions commented out in the editor.Hint
Refreshing the page may help if you get stuck.
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 variablemyVar
insidemyLocalScope
and run the tests.Note: The console will still have 'ReferenceError: myVar is not defined', but this will not cause the tests to fail.
+ \ No newline at end of file ```Show/Hide sections with changes/issues
- **`Description` section has changed** ```diff @@ -1,3 +1,7 @@In order to get the last letter of a string, you can subtract one from the string's length.
-For example, if
var firstName = "Charles"
, you can get the value of the last letter of the string by usingfirstName[firstName.length - 1]
.For example, if
var firstName = "Charles"
, you can get the value of the last letter of the string by usingfirstName[firstName.length - 1]
.Example:
+ + \ No newline at end of file ``` - **`Instructions` section has changed** ```diff @@ -1,2 +1,2 @@Use bracket notation to find the last character in the
lastName
variable.Hint
Try looking at the
lastLetterOfFirstName
variable declaration if you get stuck.Use bracket notation to find the last character in the
lastName
variable.Hint: Try looking at the example above if you get stuck.
\ No newline at end of file ```Show/Hide sections with changes/issues
- **`Description` section has changed** ```diff @@ -3,15 +3,14 @@ this.name = name; } -typeof Bird.prototype; // => object +typeof Bird.prototype; // yields 'object'Because a
-prototype
is an object, aprototype
can have its ownprototype
! In this case, theprototype
ofBird.prototype
isObject.prototype
:Show/Hide sections with changes/issues
- **`Description` section has changed** ```diff @@ -1,5 +1,5 @@In previous lessons, you learned that an object can inherit its behavior (methods) from another object by cloning its
+prototype
object:In previous lessons, you learned that an object can inherit its behavior (methods) from another object by referencing its
prototype
object:Then the
```ChildObject
received its own methods by chaining them onto itsprototype
:Show/Hide sections with changes/issues
- **Number of tests do not match - English: 7 | Chinese: 5** **Instructions:** Add or delete the applicable tests. It is possible some tests have been rearranged, so make sure each English test has a corresponding Chinese test in the same orderShow/Hide sections with changes/issues
- **`Description` section has changed** ```diff @@ -2,5 +2,4 @@Return true if the string in the first element of the array contains all of the letters of the string in the second element of the array.
For example,
["hello", "Hello"]
, should return true because all of the letters in the second string are present in the first, ignoring case.The arguments
-["hello", "hey"]
should return false because the string "hello" does not contain a "y".Lastly,
-["Alien", "line"]
, should return true because all of the letters in "line" are present in "Alien".Remember to use Read-Search-Ask if you get stuck. Write your own code.
\ No newline at end of file +Lastly,
\ No newline at end of file ``` - **The following test(s) `text` do not match:** **Instructions:** Make sure to also check that the English tests have not been reorderd. **Test 10**["Alien", "line"]
, should return true because all of the letters in "line" are present in "Alien".mutation(["ate", "date"] should return false
should return false. ```Show/Hide sections with changes/issues
- **`Description` section has changed** ```diff @@ -1,4 +1,3 @@Check if a string (first argument,
-str
) ends with the given target string (second argument,target
).This challenge can be solved with the
-.endsWith()
method, which was introduced in ES2015. But for the purpose of this challenge, we would like you to use one of the JavaScript substring methods instead.Remember to use Read-Search-Ask if you get stuck. Write your own code.
This challenge can be solved with the
\ No newline at end of file ``` - **The following test(s) `text` do not match:** **Instructions:** Make sure to also check that the English tests have not been reorderd. **Test 7**.endsWith()
method, which was introduced in ES2015. But for the purpose of this challenge, we would like you to use one of the JavaScript substring methods instead.confirmEnding("Open sesame", "pen")
should return false. ```Show/Hide sections with changes/issues
- **`Description` section has changed** ```diff @@ -1,3 +1,2 @@Truncate a string (first argument) if it is longer than the given maximum string length (second argument). Return the truncated string with a
-...
ending.Remember to use Read-Search-Ask if you get stuck. Write your own code.
Truncate a string (first argument) if it is longer than the given maximum string length (second argument). Return the truncated string with a
\ No newline at end of file ```...
ending.Show/Hide sections with changes/issues
- **`Description` section has changed** ```diff @@ -1,3 +1,2 @@Repeat a given string
-str
(first argument) fornum
times (second argument). Return an empty string ifnum
is not a positive number.Remember to use Read-Search-Ask if you get stuck. Write your own code.
Repeat a given string
\ No newline at end of file ``` - **Number of tests do not match - English: 8 | Chinese: 7** **Instructions:** Add or delete the applicable tests. It is possible some tests have been rearranged, so make sure each English test has a corresponding Chinese test in the same orderstr
(first argument) fornum
times (second argument). Return an empty string ifnum
is not a positive number. For the purpose of this challenge, do not use the built-in.repeat()
method.Show/Hide sections with changes/issues
- **`Description` section has changed** ```diff @@ -1,4 +1,3 @@Check if a value is classified as a boolean primitive. Return true or false.
-Boolean primitives are true and false.
-Remember to use Read-Search-Ask if you get stuck. Try to pair program. Write your own code.
Boolean primitives are true and false.
\ No newline at end of file ```Show/Hide sections with changes/issues
- **`Description` section has changed** ```diff @@ -1,5 +1,4 @@Return the lowest index at which a value (second argument) should be inserted into an array (first argument) once it has been sorted. The returned value should be a number.
For example,
-getIndexToIns([1,2,3,4], 1.5)
should return1
because it is greater than1
(index 0), but less than2
(index 1).Likewise,
-getIndexToIns([20,3,5], 19)
should return2
because once the array has been sorted it will look like[3,5,20]
and19
is less than20
(index 2) and greater than5
(index 1).Remember to use Read-Search-Ask if you get stuck. Write your own code.
Likewise,
\ No newline at end of file ```getIndexToIns([20,3,5], 19)
should return2
because once the array has been sorted it will look like[3,5,20]
and19
is less than20
(index 2) and greater than5
(index 1).Show/Hide sections with changes/issues
- **`Description` section has changed** ```diff @@ -1,3 +1,2 @@Write a function that splits an array (first argument) into groups the length of
-size
(second argument) and returns them as a two-dimensional array.Remember to use Read-Search-Ask if you get stuck. Write your own code.
Write a function that splits an array (first argument) into groups the length of
\ No newline at end of file ```size
(second argument) and returns them as a two-dimensional array.Show/Hide sections with changes/issues
- **`Description` section has changed** ```diff @@ -3,5 +3,4 @@If the integer is represented with the letter n, a factorial is the product of all positive integers less than or equal to n.
Factorials are often represented with the shorthand notation
n!
For example:
-5! = 1 * 2 * 3 * 4 * 5 = 120
Only integers greater than or equal to zero will be supplied to the function.
-Remember to use Read-Search-Ask if you get stuck. Write your own code.
\ No newline at end of file +Only integers greater than or equal to zero will be supplied to the function.
\ No newline at end of file ```Show/Hide sections with changes/issues
- **`Description` section has changed** ```diff @@ -1,4 +1,3 @@Return the length of the longest word in the provided sentence.
-Your response should be a number.
-Remember to use Read-Search-Ask if you get stuck. Write your own code.
Your response should be a number.
\ No newline at end of file ```Show/Hide sections with changes/issues
- **`Description` section has changed** ```diff @@ -1,4 +1,3 @@Return the provided string with the first letter of each word capitalized. Make sure the rest of the word is in lower case.
-For the purpose of this exercise, you should also capitalize connecting words like "the" and "of".
-Remember to use Read-Search-Ask if you get stuck. Write your own code.
For the purpose of this exercise, you should also capitalize connecting words like "the" and "of".
\ No newline at end of file ```Show/Hide sections with changes/issues
- **`Description` section has changed** ```diff @@ -1,5 +1,4 @@Remove all falsy values from an array.
Falsy values in JavaScript are
-false
,null
,0
,""
,undefined
, andNaN
.Hint: Try converting each value to a Boolean.
-Remember to use Read-Search-Ask if you get stuck. Write your own code.
Hint: Try converting each value to a Boolean.
\ No newline at end of file ``` - **The following test(s) `text` do not match:** **Instructions:** Make sure to also check that the English tests have not been reorderd. **Test 4**bouncer([1, null, NaN, 2, undefined])
should return[1, 2]
. ```Show/Hide sections with changes/issues
- **`Description` section has changed** ```diff @@ -1,6 +1,5 @@You are given two arrays and an index.
-Use the array methods
+slice
andsplice
to copy each element of the first array into the second array, in order.Copy each element of the first array into the second array, in order.
Begin inserting elements at index
-n
of the second array.Return the resulting array. The input arrays should remain the same after the function runs.
-Remember to use Read-Search-Ask if you get stuck. Write your own code.
Return the resulting array. The input arrays should remain the same after the function runs.
\ No newline at end of file ```Show/Hide sections with changes/issues
- **`Description` section has changed** ```diff @@ -1,4 +1,3 @@Return an array consisting of the largest number from each provided sub-array. For simplicity, the provided array will contain exactly 4 sub-arrays.
-Remember, you can iterate through an array with a simple for loop, and access each member with array syntax
-arr[i]
.Remember to use Read-Search-Ask if you get stuck. Write your own code.
Remember, you can iterate through an array with a simple for loop, and access each member with array syntax
\ No newline at end of file ```arr[i]
.Show/Hide sections with changes/issues
- **`Description` section has changed** ```diff @@ -1,3 +1,3 @@Create a function that looks through an array (first argument) and returns the first element in the array that passes a truth test (second argument). If no element passes the test, return undefined.
-Remember to use Read-Search-Ask if you get stuck. Try to pair program. Write your own code.
Create a function that looks through an array
+ \ No newline at end of file ```arr
and returns the first element in it that passes a 'truth test'. This means that given an elementx
, the 'truth test' is passed iffunc(x)
istrue
. If no element passes the test, returnundefined
.Show/Hide sections with changes/issues
- **`Description` section has changed** ```diff @@ -1,5 +1,4 @@Reverse the provided string.
You may need to turn the string into an array before you can reverse it.
-Your result must be a string.
-Remember to use Read-Search-Ask if you get stuck. Write your own code.
Your result must be a string.
\ No newline at end of file ```Show/Hide sections with changes/issues
- **The following test(s) `text` do not match:** **Instructions:** Make sure to also check that the English tests have not been reorderd. **Test 1**htmlColorNames
should return["DarkSalmon", "BlanchedAlmond", "LavenderBlush", "PaleTurqoise", "FireBrick"]
```Show/Hide sections with changes/issues
- **`Description` section has changed** ```diff @@ -1,18 +1,29 @@At their most basic, objects are just collections of key-value pairs, or in other words, pieces of data mapped to unique identifiers that we call properties or keys. Let's take a look at a very simple example:
Using the same syntax, we can also add new key-value pairs to objects. We've created a
foods
object with three entries. Add three more entries:bananas
with a value of13
,grapes
with a value of35
, andstrawberries
with a value of27
.A
\ No newline at end of file ```foods
object has been created with three entries. Using the syntax of your choice, add three more entries to it:bananas
with a value of13
,grapes
with a value of35
, andstrawberries
with a value of27
.Show/Hide sections with changes/issues
- **`Description` section has changed** ```diff @@ -7,10 +7,13 @@ online: 80, onlineStatus: { active: 67, - away: 13 + away: 13, + busy: 8 } } }; -
+nestedObject
has three unique keys:id
, whose value is a number,date
whose value is a string, anddata
, whose value is an object which has yet another object nested within it. While structures can quickly become complex, we can still use the same notations to access the information we need.
+ \ No newline at end of file ``` - **`Instructions` section has changed** ```diff @@ -1,2 +1,2 @@nestedObject
has three properties:id
(value is a number),date
(value is a string), anddata
(value is an object with its nested structure). While structures can quickly become complex, we can still use the same notations to access the information we need. To assign the value10
to thebusy
property of the nestedonlineStatus
object, we use dot notation to reference the property:Here we've defined an object,
userActivity
, which includes another object nested within it. You can modify properties on this nested object in the same way you modified properties in the last challenge. Set the value of theonline
key to45
.Here we've defined an object
\ No newline at end of file ```userActivity
, which includes another object nested within it. Set the value of theonline
key to45
.Show/Hide sections with changes/issues
- **Number of tests do not match - English: 6 | Chinese: 5** **Instructions:** Add or delete the applicable tests. It is possible some tests have been rearranged, so make sure each English test has a corresponding Chinese test in the same orderShow/Hide sections with changes/issues
- **`Description` section has changed** ```diff @@ -1,5 +1,5 @@The next method we will cover is
slice()
.slice()
, rather than modifying an array, copies, or extracts, a given number of elements to a new array, leaving the array it is called upon untouched.slice()
takes only 2 parameters — the first is the index at which to begin extraction, and the second is the index at which to stop extraction (extraction will occur up to, but not including the element at this index). Consider this:Show/Hide sections with changes/issues
- **`Description` section has changed** ```diff @@ -3,6 +3,6 @@In practice, we can use the spread operator to copy an array like so:
\ No newline at end of file ```Show/Hide sections with changes/issues
- **`Description` section has changed** ```diff @@ -2,5 +2,4 @@One of the simplest and most widely known ciphers is a Caesar cipher, also known as a shift cipher. In a shift cipher the meanings of the letters are shifted by some set amount.
A common modern use is the ROT13 cipher, where the values of the letters are shifted by 13 places. Thus 'A' ↔ 'N', 'B' ↔ 'O' and so on.
Write a function which takes a ROT13 encoded string as input and returns a decoded string.
-All letters will be uppercase. Do not transform any non-alphabetic character (i.e. spaces, punctuation), but do pass them on.
-Remember to use Read-Search-Ask if you get stuck. Try to pair program. Write your own code.
\ No newline at end of file +All letters will be uppercase. Do not transform any non-alphabetic character (i.e. spaces, punctuation), but do pass them on.
\ No newline at end of file ```Show/Hide sections with changes/issues
- **`Description` section has changed** ```diff @@ -2,5 +2,4 @@Return
true
if the given string is a palindrome. Otherwise, returnfalse
.A palindrome is a word or sentence that's spelled the same way both forward and backward, ignoring punctuation, case, and spacing.
Note
You'll need to remove all non-alphanumeric characters (punctuation, spaces and symbols) and turn everything into the same case (lower or upper case) in order to check for palindromes.
We'll pass strings with varying formats, such as
-"racecar"
,"RaceCar"
, and"race CAR"
among others.We'll also pass strings with special symbols, such as
-"2A3*3a2"
,"2A3 3a2"
, and"2_A3*3#A2"
.Remember to use Read-Search-Ask if you get stuck. Write your own code.
\ No newline at end of file +We'll also pass strings with special symbols, such as
\ No newline at end of file ```"2A3*3a2"
,"2A3 3a2"
, and"2_A3*3#A2"
.Show/Hide sections with changes/issues
- **`Description` section has changed** ```diff @@ -3,6 +3,18 @@The
checkCashRegister()
function should always return an object with astatus
key and achange
key.Return
{status: "INSUFFICIENT_FUNDS", change: []}
if cash-in-drawer is less than the change due, or if you cannot return the exact change.Return
-{status: "CLOSED", change: [...]}
with cash-in-drawer as the value for the keychange
if it is equal to the change due.Otherwise, return
-{status: "OPEN", change: [...]}
, with the change due in coins and bills, sorted in highest to lowest order, as the value of thechange
key.Remember to use Read-Search-Ask if you get stuck. Try to pair program. Write your own code.
Otherwise, return
{status: "OPEN", change: [...]}
, with the change due in coins and bills, sorted in highest to lowest order, as the value of thechange
key.See below for an example of a cash-in-drawer array:
+ \ No newline at end of file ```Show/Hide sections with changes/issues
- **`Description` section has changed** ```diff @@ -1,5 +1,4 @@Return
true
if the passed string looks like a valid US phone number.The user may fill out the form field any way they choose as long as it has the format of a valid US number. The following are examples of valid formats for US numbers (refer to the tests below for other variants):
-For this challenge you will be presented with a string such as
-800-692-7753
or8oo-six427676;laskdjf
. Your job is to validate or reject the US phone number based on any combination of the formats provided above. The area code is required. If the country code is provided, you must confirm that the country code is1
. Returntrue
if the string is a valid US phone number; otherwise returnfalse
.Remember to use Read-Search-Ask if you get stuck. Try to pair program. Write your own code.
For this challenge you will be presented with a string such as
\ No newline at end of file ```800-692-7753
or8oo-six427676;laskdjf
. Your job is to validate or reject the US phone number based on any combination of the formats provided above. The area code is required. If the country code is provided, you must confirm that the country code is1
. Returntrue
if the string is a valid US phone number; otherwise returnfalse
.Show/Hide sections with changes/issues
- **`Description` section has changed** ```diff @@ -1,4 +1,3 @@Convert the given number into a roman numeral.
-All roman numerals answers should be provided in upper-case.
-Remember to use Read-Search-Ask if you get stuck. Try to pair program. Write your own code.
All roman numerals answers should be provided in upper-case.
\ No newline at end of file ```Show/Hide sections with changes/issues
- **Number of tests do not match - English: 5 | Chinese: 6** **Instructions:** Add or delete the applicable tests. It is possible some tests have been rearranged, so make sure each English test has a corresponding Chinese test in the same orderShow/Hide sections with changes/issues
- **Number of tests do not match - English: 3 | Chinese: 2** **Instructions:** Add or delete the applicable tests. It is possible some tests have been rearranged, so make sure each English test has a corresponding Chinese test in the same orderShow/Hide sections with changes/issues
- **`Description` section has changed** ```diff @@ -1,3 +1,2 @@It would teach us a lot about the
-filter
method if we try to implement a version of it that behaves exactly likeArray.prototype.filter()
. It can use either afor
loop orArray.prototype.forEach()
.Note: A pure function is allowed to alter local variables defined within its scope, although, it's preferable to avoid that as well.
You might learn a lot about the
\ No newline at end of file ``` - **`Instructions` section has changed** ```diff @@ -1,2 +1,2 @@filter
method if you implement your own version of it. It is recommended you use afor
loop orArray.prototype.forEach()
.Write your own
Array.prototype.myFilter()
, which should behave exactly likeArray.prototype.filter()
. You may use afor
loop or theArray.prototype.forEach()
method.Write your own
\ No newline at end of file ```Array.prototype.myFilter()
, which should behave exactly likeArray.prototype.filter()
. You should not use the built-infilter
method. TheArray
instance can be accessed in themyFilter
method usingthis
.Show/Hide sections with changes/issues
- **`Instructions` section has changed** ```diff @@ -1,3 +1,3 @@Let's update the
-incrementer
function to clearly declare its dependencies.Write the
incrementer
function so it takes an argument, and then increases the value by one.Write the
\ No newline at end of file ``` - **The following test(s) `text` do not match:** **Instructions:** Make sure to also check that the English tests have not been reorderd. **Test 1**incrementer
function so it takes an argument, and then returns a result after increasing the value by one.incrementer
should not change the value offixedValue
. ```incrementer
function should take a parameter. ```Show/Hide sections with changes/issues
- **The following test(s) `text` do not match:** **Instructions:** Make sure to also check that the English tests have not been reorderd. **Test 2**Show/Hide sections with changes/issues
- **Number of tests do not match - English: 5 | Chinese: 4** **Instructions:** Add or delete the applicable tests. It is possible some tests have been rearranged, so make sure each English test has a corresponding Chinese test in the same orderShow/Hide sections with changes/issues
- **`Description` section has changed** ```diff @@ -1,5 +1,4 @@As you have seen from applying
Array.prototype.map()
, or simplymap()
earlier, themap
method returns an array of the same length as the one it was called on. It also doesn't alter the original array, as long as its callback function doesn't.In other words,
-map
is a pure function, and its output depends solely on its inputs. Plus, it takes another function as its argument.It would teach us a lot about
-map
to try to implement a version of it that behaves exactly like theArray.prototype.map()
with afor
loop orArray.prototype.forEach()
.Note: A pure function is allowed to alter local variables defined within its scope, although, it's preferable to avoid that as well.
You might learn a lot about the
\ No newline at end of file ``` - **`Instructions` section has changed** ```diff @@ -1,2 +1,2 @@map
method if you implement your own version of it. It is recommended you use afor
loop orArray.prototype.forEach()
.Write your own
Array.prototype.myMap()
, which should behave exactly likeArray.prototype.map()
. You may use afor
loop or theforEach
method.Write your own
\ No newline at end of file ```Array.prototype.myMap()
, which should behave exactly likeArray.prototype.map()
. You should not use the built-inmap
method. TheArray
instance can be accessed in themyMap
method usingthis
.Show/Hide sections with changes/issues
- **`Description` section has changed** ```diff @@ -1,5 +1,5 @@So far, we have seen two distinct principles for functional programming:
-1) Don't alter a variable or object - create new variables and objects and return them if need be from a function.
-2) Declare function arguments - any computation inside a function depends only on the arguments, and not on any global object or variable.
+1) Don't alter a variable or object - create new variables and objects and return them if need be from a function. Hint: using something like
+var newArr = arrVar
, wherearrVar
is an array will simply create a reference to the existing variable and not a copy. So changing a value innewArr
would change the value inarrVar
.2) Declare function parameters - any computation inside a function depends only on the arguments passed to the function, and not on any global object or variable.
Adding one to a number is not very exciting, but we can apply these principles when working with arrays or more complex objects.
Rewrite the code so the global array
bookList
is not changed inside either function. Theadd
function should add the givenbookName
to the end of an array. Theremove
function should remove the givenbookName
from an array. Both functions should return an array, and any new parameters should be added before thebookName
parameter.Rewrite the code so the global array
bookList
is not changed inside either function. Theadd
function should add the givenbookName
to the end of the array passed to it and return a new array (list). Theremove
function should remove the givenbookName
from the array passed to it.Note: Both functions should return an array, and any new parameters should be added before the
+ \ No newline at end of file ```bookName
parameter.Show/Hide sections with changes/issues
- **Number of tests do not match - English: 4 | Chinese: 3** **Instructions:** Add or delete the applicable tests. It is possible some tests have been rearranged, so make sure each English test has a corresponding Chinese test in the same orderShow/Hide sections with changes/issues
- **`Description` section has changed** ```diff @@ -1,8 +1,7 @@The
const
declaration has many use cases in modern JavaScript.Some developers prefer to assign all their variables using
-const
by default, unless they know they will need to reassign the value. Only in that case, they uselet
.However, it is important to understand that objects (including arrays and functions) assigned to a variable using
const
are still mutable. Using theconst
declaration only prevents reassignment of the variable identifier.Show/Hide sections with changes/issues
- **`Description` section has changed** ```diff @@ -4,5 +4,4 @@ });
-error
is the argument passed in to thereject
method.Note: the
\ No newline at end of file ```then
andcatch
methods can be chained to the promise declaration if you choose.Show/Hide sections with changes/issues
- **`Description` section has changed** ```diff @@ -1,6 +1,5 @@The keyword
let
is not the only new way to declare variables. In ES6, you can also declare variables using theconst
keyword.const
has all the awesome features thatlet
has, with the added bonus that variables declared usingconst
are read-only. They are a constant value, which means that once a variable is assigned withconst
, it cannot be reassigned.Show/Hide sections with changes/issues
- **`Description` section has changed** ```diff @@ -14,5 +14,5 @@When there is no function body, and only a return value, arrow function syntax allows you to omit the keyword
-return
as well as the brackets surrounding the code. This helps simplify smaller functions into one-line statements:This code will still return
+value
by default.This code will still return the string
\ No newline at end of file ``` - **`Instructions` section has changed** ```diff @@ -1,2 +1,2 @@value
by default.Rewrite the function assigned to the variable
magic
which returns a newDate()
to use arrow function syntax. Also make sure nothing is defined using the keywordvar
.Rewrite the function assigned to the variable
\ No newline at end of file ```magic
which returns anew Date()
to use arrow function syntax. Also, make sure nothing is defined using the keywordvar
.Show/Hide sections with changes/issues
- **Number of tests do not match - English: 4 | Chinese: 3** **Instructions:** Add or delete the applicable tests. It is possible some tests have been rearranged, so make sure each English test has a corresponding Chinese test in the same orderShow/Hide sections with changes/issues
- **`Description` section has changed** ```diff @@ -1,13 +1,15 @@Just like a regular function, you can pass arguments into an arrow function.
-If an arrow function has a single argument, the parentheses enclosing the argument may be omitted.
-myConcat
should be a function. ```Show/Hide sections with changes/issues
- **`Description` section has changed** ```diff @@ -10,6 +10,5 @@ /* do something with these fields */ } -This removes some extra lines and makes our code look neat. -This has the added benefit of not having to manipulate an entire object in a function — only the fields that are needed are copied inside the function.
+When
\ No newline at end of file ```profileData
is passed to the above function, the values are destructured from the function parameter for use within the function.Show/Hide sections with changes/issues
- **`Description` section has changed** ```diff @@ -34,8 +34,7 @@ console.log(printNumTwo()); // returns 3As you can see,
-printNumTwo()
prints 3 and not 2. This is because the value assigned toi
was updated and theprintNumTwo()
returns the globali
and not the valuei
had when the function was created in the for loop. Thelet
keyword does not follow this behavior:Show/Hide sections with changes/issues
- **The following test(s) `text` do not match:** **Instructions:** Make sure to also check that the English tests have not been reorderd. **Test 1**resolve
should be executed when theif
condition istrue
. ```reject
should be executed when theif
condition isfalse
. ```Show/Hide sections with changes/issues
- **`Instructions` section has changed** ```diff @@ -1,3 +1,9 @@Use template literal syntax with backticks to display each entry of the
-result
object'sfailure
array. Each entry should be wrapped inside anli
element with the class attributetext-warning
, and listed within theresultDisplayArray
.Use an iterator method (any kind of loop) to get the desired output.
Use template literal syntax with backticks to create an array of list element (
+li
) strings. Each list element's text should be one of the array elements from thefailure
property on theresult
object and have aclass
attribute with the valuetext-warning
. ThemakeList
function should return the array of list item strings.Use an iterator method (any kind of loop) to get the desired output (shown below).
+ \ No newline at end of file ``` - **The following test(s) `text` do not match:** **Instructions:** Make sure to also check that the English tests have not been reorderd. **Test 1**resultDisplayArray
should be an array containingresult failure
messages. ```resultDisplayArray
should be equal to the specified output. ```Show/Hide sections with changes/issues
- **Number of tests do not match - English: 4 | Chinese: 3** **Instructions:** Add or delete the applicable tests. It is possible some tests have been rearranged, so make sure each English test has a corresponding Chinese test in the same orderShow/Hide sections with changes/issues
- **`Description` section has changed** ```diff @@ -4,6 +4,6 @@ console.log(a, b); // 1, 2 console.log(arr); // [3, 4, 5, 7] -Variables
+a
andb
take the first and second values from the array. After that, because of rest parameter's presence,arr
gets rest of the values in the form of an array. -The rest element only works correctly as the last variable in the list. As in, you cannot use the rest parameter to catch a subarray that leaves out last element of the original array.Variables
\ No newline at end of file ``` - **Number of tests do not match - English: 4 | Chinese: 3** **Instructions:** Add or delete the applicable tests. It is possible some tests have been rearranged, so make sure each English test has a corresponding Chinese test in the same ordera
andb
take the first and second values from the array. After that, because of the rest parameter's presence,arr
gets the rest of the values in the form of an array. +The rest element only works correctly as the last variable in the list. As in, you cannot use the rest parameter to catch a subarray that leaves out the last element of the original array.Show/Hide sections with changes/issues
- **`Description` section has changed** ```diff @@ -16,10 +16,10 @@ this._author = updatedAuthor; } } -const lol = new Book('anonymous'); -console.log(lol.writer); // anonymous -lol.writer = 'wut'; -console.log(lol.writer); // wut +const novel = new Book('anonymous'); +console.log(novel.writer); // anonymous +novel.writer = 'newAuthor'; +console.log(novel.writer); // newAuthorNotice the syntax used to invoke the getter and setter. They do not even look like functions. Getters and setters are important because they hide internal implementation details. ``` - **`Instructions` section has changed** ```diff @@ -1,6 +1,6 @@
\ No newline at end of file
```
- **Number of tests do not match - English: 7 | Chinese: 6**
**Instructions:** Add or delete the applicable tests. It is possible some tests have been rearranged, so make sure each English test has a corresponding Chinese test in the same order
Use the
-class
keyword to create a Thermostat class. The constructor accepts a Fahrenheit temperature.Now create a
+getter
and asetter
in the class, to obtain the temperature in Celsius.In the class, create a
getter
to obtain the temperature in Celsius and asetter
to set the temperature in Celsius.Remember that
C = 5/9 * (F - 32)
andF = C * 9.0 / 5 + 32
, whereF
is the value of temperature in Fahrenheit, andC
is the value of the same temperature in Celsius.Note: When you implement this, you will track the temperature inside the class in one scale, either Fahrenheit or Celsius.
This is the power of a getter and a setter. You are creating an API for another user, who can get the correct result regardless of which one you track.
In other words, you are abstracting implementation details from the user.
Thanks @RandellDawson for opening this issue!