Skip to content

Commit 8dc3c26

Browse files
committed
chore: Add character and word counting examples to README.md
1 parent 13a5438 commit 8dc3c26

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

README.md

+28
Original file line numberDiff line numberDiff line change
@@ -9420,6 +9420,34 @@ console.log("Current year: " + year);
94209420
// Output: Current year: 2024
94219421
```
94229422
9423+
Count the character 'l' in the string "Hello, World!"
9424+
9425+
```javascript
9426+
const str = "Hello, World!";
9427+
9428+
let count = 0;
9429+
9430+
for (let i = 0; i < str.length; i++) {
9431+
if (str[i] === 'l') {
9432+
count++;
9433+
}
9434+
}
9435+
9436+
console.log("The number of occurrences of 'l' in the string is: " + count);
9437+
// Output: The number of occurrences of 'l' in the string is: 3
9438+
```
9439+
9440+
Count the number of words in the string "Hello, World!"
9441+
9442+
```javascript
9443+
const str = "Hello, World!";
9444+
9445+
const words = str.split(" ");
9446+
9447+
console.log("The number of words in the string is: " + words.length);
9448+
// Output: The number of words in the string is: 2
9449+
```
9450+
94239451
[Back to Top⤴️](#table-of-contents)
94249452
94259453
## List of GitHub Repositories to learn JavaScript

0 commit comments

Comments
 (0)