diff --git a/content/javascript/concepts/strings/terms/charAt/charAt.md b/content/javascript/concepts/strings/terms/charAt/charAt.md index d5002b508ee..8905cb96153 100644 --- a/content/javascript/concepts/strings/terms/charAt/charAt.md +++ b/content/javascript/concepts/strings/terms/charAt/charAt.md @@ -16,11 +16,11 @@ Returns a single character at the specified index of a string. ## Syntax -```js +```pseudo string.charAt(index); ``` -`index` is a required parameter representing the index of the character you want to return. +`index` is a required parameter representing the index of the character to be returned. ## Examples @@ -45,3 +45,17 @@ const lastLetter = greeting.charAt(greeting.length - 1); console.log(lastLetter); // Output: d ``` + +## Codebyte Example + +The following is runnable, and demonstrates the use of the `.charAt()` method: + +```codebyte/javascript +const myString = 'I love JavaScript! '; + +// Using integer value +console.log(myString.charAt(2)); + +// Using decimal value that gets rounded down from 3.5 to 3 +console.log(myString.charAt(3.5)); +``` diff --git a/content/javascript/concepts/strings/terms/concat/concat.md b/content/javascript/concepts/strings/terms/concat/concat.md index 596df3194d1..c18b1bddc54 100644 --- a/content/javascript/concepts/strings/terms/concat/concat.md +++ b/content/javascript/concepts/strings/terms/concat/concat.md @@ -16,7 +16,7 @@ Concatenates or combines strings together. ## Syntax -```js +```pseudo string.concat(string_1, string_2, string_3); ``` @@ -25,8 +25,8 @@ string.concat(string_1, string_2, string_3); Concatenating a string: ```js -console.log('Do you like Latte or '.concat('Cappuccino?')); -// Output: Do you like Latte or Cappuccino? +console.log('Would you like a latte or '.concat('cappuccino?')); +// Output: Would you like a latte or cappuccino? ``` ## Example 2 @@ -34,9 +34,23 @@ console.log('Do you like Latte or '.concat('Cappuccino?')); Concatenating strings with the usage of variables: ```js -const x = 'Do you like Latte or'; -const y = 'Cappuccino?'; +const x = 'Would you like a latte or'; +const y = 'cappuccino?'; console.log('Hey Bob! '.concat(x, ' ', y)); -// Output: Hey Bob! Do you like Latte or Cappuccino? +// Output: Hey Bob! Would you like a latte or cappuccino? +``` + +## Codebyte Example + +The following is runnable, and demonstrates the use of the `.concat()` method: + +```codebyte/javascript +// Concatenating a string directly: +console.log('I love JavaScript'.concat(' and Go')); + +// Concatenating strings using variables +const myString = 'I love JavaScript ' +const myString2 = 'and Go'; +console.log(myString.concat(myString2)); ``` diff --git a/content/javascript/concepts/strings/terms/indexOf/indexOf.md b/content/javascript/concepts/strings/terms/indexOf/indexOf.md index 3ecaac51f67..af2a8b65c9f 100644 --- a/content/javascript/concepts/strings/terms/indexOf/indexOf.md +++ b/content/javascript/concepts/strings/terms/indexOf/indexOf.md @@ -1,6 +1,6 @@ --- Title: '.indexOf()' -Description: 'Searches a string for a given value and returns the first index if found. Returns -1 if not found.' +Description: 'Searches a string for a given value and returns the first index if found.' Subjects: - 'Web Development' - 'Computer Science' @@ -16,7 +16,7 @@ Searches a string for a given value and returns the first index if found. Return ## Syntax -```js +```pseudo string.indexOf(value, startSearch); ``` @@ -70,3 +70,18 @@ const didYouFindWaldo = people.indexOf('Waldo'); console.log(didYouFindWaldo); // Output: -1 ``` + +## Codebyte Example + +The following is runnable, and demonstrates the use of the `.indexOf()` method: + +```codebyte/javascript +// Declaring a string +const myString = 'I love JavaScript! '; + +// Case 1: Target value exists +console.log(myString.indexOf('love')); + +// Case 2: Target value does not exist +console.log(myString.indexOf('hate')); +```