Skip to content

Commit ecd416f

Browse files
mehboobali98caupolicandiazSSwiniarski
authored
Add js string codebytes (#2580)
* js codebyte added for charAt * js code bytes added for concat * type fixed in charAt js codebyte * js codebytes added for indexOf * remove array codebyte example * fixed typo * review edits --------- Co-authored-by: Caupolican Diaz <caupolicandiaz@gmail.com> Co-authored-by: SSwiniarski <86081858+SSwiniarski@users.noreply.github.com>
1 parent 248d224 commit ecd416f

File tree

3 files changed

+53
-10
lines changed

3 files changed

+53
-10
lines changed

content/javascript/concepts/strings/terms/charAt/charAt.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ Returns a single character at the specified index of a string.
1616

1717
## Syntax
1818

19-
```js
19+
```pseudo
2020
string.charAt(index);
2121
```
2222

23-
`index` is a required parameter representing the index of the character you want to return.
23+
`index` is a required parameter representing the index of the character to be returned.
2424

2525
## Examples
2626

@@ -45,3 +45,17 @@ const lastLetter = greeting.charAt(greeting.length - 1);
4545
console.log(lastLetter);
4646
// Output: d
4747
```
48+
49+
## Codebyte Example
50+
51+
The following is runnable, and demonstrates the use of the `.charAt()` method:
52+
53+
```codebyte/javascript
54+
const myString = 'I love JavaScript! ';
55+
56+
// Using integer value
57+
console.log(myString.charAt(2));
58+
59+
// Using decimal value that gets rounded down from 3.5 to 3
60+
console.log(myString.charAt(3.5));
61+
```

content/javascript/concepts/strings/terms/concat/concat.md

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Concatenates or combines strings together.
1616

1717
## Syntax
1818

19-
```js
19+
```pseudo
2020
string.concat(string_1, string_2, string_3);
2121
```
2222

@@ -25,18 +25,32 @@ string.concat(string_1, string_2, string_3);
2525
Concatenating a string:
2626

2727
```js
28-
console.log('Do you like Latte or '.concat('Cappuccino?'));
29-
// Output: Do you like Latte or Cappuccino?
28+
console.log('Would you like a latte or '.concat('cappuccino?'));
29+
// Output: Would you like a latte or cappuccino?
3030
```
3131

3232
## Example 2
3333

3434
Concatenating strings with the usage of variables:
3535

3636
```js
37-
const x = 'Do you like Latte or';
38-
const y = 'Cappuccino?';
37+
const x = 'Would you like a latte or';
38+
const y = 'cappuccino?';
3939

4040
console.log('Hey Bob! '.concat(x, ' ', y));
41-
// Output: Hey Bob! Do you like Latte or Cappuccino?
41+
// Output: Hey Bob! Would you like a latte or cappuccino?
42+
```
43+
44+
## Codebyte Example
45+
46+
The following is runnable, and demonstrates the use of the `.concat()` method:
47+
48+
```codebyte/javascript
49+
// Concatenating a string directly:
50+
console.log('I love JavaScript'.concat(' and Go'));
51+
52+
// Concatenating strings using variables
53+
const myString = 'I love JavaScript '
54+
const myString2 = 'and Go';
55+
console.log(myString.concat(myString2));
4256
```

content/javascript/concepts/strings/terms/indexOf/indexOf.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
Title: '.indexOf()'
3-
Description: 'Searches a string for a given value and returns the first index if found. Returns -1 if not found.'
3+
Description: 'Searches a string for a given value and returns the first index if found.'
44
Subjects:
55
- 'Web Development'
66
- 'Computer Science'
@@ -16,7 +16,7 @@ Searches a string for a given value and returns the first index if found. Return
1616

1717
## Syntax
1818

19-
```js
19+
```pseudo
2020
string.indexOf(value, startSearch);
2121
```
2222

@@ -70,3 +70,18 @@ const didYouFindWaldo = people.indexOf('Waldo');
7070
console.log(didYouFindWaldo);
7171
// Output: -1
7272
```
73+
74+
## Codebyte Example
75+
76+
The following is runnable, and demonstrates the use of the `.indexOf()` method:
77+
78+
```codebyte/javascript
79+
// Declaring a string
80+
const myString = 'I love JavaScript! ';
81+
82+
// Case 1: Target value exists
83+
console.log(myString.indexOf('love'));
84+
85+
// Case 2: Target value does not exist
86+
console.log(myString.indexOf('hate'));
87+
```

0 commit comments

Comments
 (0)