File tree 1 file changed +28
-0
lines changed
1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -9420,6 +9420,34 @@ console.log("Current year: " + year);
9420
9420
// Output: Current year: 2024
9421
9421
` ` `
9422
9422
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
+
9423
9451
[Back to Top⤴️](#table-of-contents)
9424
9452
9425
9453
## List of GitHub Repositories to learn JavaScript
You can’t perform that action at this time.
0 commit comments