mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-06-19 21:09:51 +08:00
fix: js replace parts of a string with another multiple choice question (#57558)
This commit is contained in:
parent
60068cd407
commit
dbf873f449
@ -50,35 +50,42 @@ Think about what happens when there are multiple instances of the word you are t
|
||||
|
||||
## --text--
|
||||
|
||||
How can you replace all instances of a word in a string?
|
||||
What will the following code output?
|
||||
|
||||
```js
|
||||
let phrase = "freeCodeCamp is awesome!";
|
||||
let updatedPhrase = phrase.replace("freecodecamp", "fCC");
|
||||
|
||||
console.log(updatedPhrase);
|
||||
```
|
||||
|
||||
## --answers--
|
||||
|
||||
Use a `for` loop.
|
||||
`"fcc is awesome!"`
|
||||
|
||||
### --feedback--
|
||||
|
||||
Consider how regular expressions can help with multiple replacements.
|
||||
Remember that the `replace()` method is case-sensitive.
|
||||
|
||||
---
|
||||
|
||||
Use `replace()` with a case-sensitive string.
|
||||
`"fCC is awesome!"`
|
||||
|
||||
### --feedback--
|
||||
|
||||
Consider how regular expressions can help with multiple replacements.
|
||||
Remember that the `replace()` method is case-sensitive.
|
||||
|
||||
---
|
||||
|
||||
Use `replace()` with a global regular expression.
|
||||
`"freeCodeCamp is awesome!"`
|
||||
|
||||
---
|
||||
|
||||
Use `replaceAll()` instead of `replace()`.
|
||||
`undefined`
|
||||
|
||||
### --feedback--
|
||||
|
||||
Consider how regular expressions can help with multiple replacements.
|
||||
Remember that the `replace()` method is case-sensitive.
|
||||
|
||||
## --video-solution--
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user