fix: js replace parts of a string with another multiple choice question (#57558)

This commit is contained in:
Kristofer Koishigawa 2024-12-17 22:05:29 +09:00 committed by GitHub
parent 60068cd407
commit dbf873f449
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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--