mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-05-28 18:26:54 +00:00
fix(curriculum): update string method lesson to include variable usage example (#66229)
This commit is contained in:
committed by
GitHub
parent
3888a601ad
commit
b8ae304f76
+15
@@ -75,6 +75,21 @@ The `repeat()` method can simplify tasks that involve string duplication, making
|
||||
|
||||
Whether you're generating repeated text patterns or filling a space with characters, `repeat()` can save you from writing loops or more complex code.
|
||||
|
||||
You are not limited to passing a number directly into the `repeat()` method. You can also pass a variable that stores a number value.
|
||||
|
||||
:::interactive_editor
|
||||
|
||||
```js
|
||||
let count = 4;
|
||||
let word = "Test";
|
||||
let repeatedWord = word.repeat(count);
|
||||
console.log(repeatedWord); // TestTestTestTest
|
||||
```
|
||||
|
||||
:::
|
||||
|
||||
In this example, the `count` variable stores the number of repetitions. This can be useful when the number of repetitions depends on user input or other dynamic values in your program.
|
||||
|
||||
# --questions--
|
||||
|
||||
## --text--
|
||||
|
||||
Reference in New Issue
Block a user