String Flashcards

1
Q

const sentence = ‘The quick brown fox jumps over the lazy dog.’;

const index = 4;

console.log(The character at index ${index} is ${sentence.charAt(index)});

A

// expected output: “The character at index 4 is q”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q
const str1 = 'Hello';
const str2 = 'World';

console. log(str1.concat(‘ ‘, str2));
console. log(str2.concat(‘, ‘, str1));

A

// expected output: “Hello World”

// expected output: “World, Hello”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

const str1 = ‘Cats are the best!’;

console.log(str1.endsWith(‘best’, 17));

const str2 = ‘Is this a question’;

console.log(str2.endsWith(‘?’));

A

// expected output: true

// expected output: false

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

const sentence = ‘The quick brown fox jumps over the lazy dog.’;

const word = ‘fox’;

console.log(The word "${word}" ${sentence.includes(word) ? 'is' : 'is not'} in the sentence);

A

// expected output: “The word “fox” is in the sentence”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

const paragraph = ‘The quick brown fox jumps over the lazy dog. If the dog barked, was it really lazy?’;

const searchTerm = 'dog';
const indexOfFirst = paragraph.indexOf(searchTerm);

console. log(The index of the first "${searchTerm}" from the beginning is ${indexOfFirst});
console. log(The index of the 2nd "${searchTerm}" is ${paragraph.indexOf(searchTerm, (indexOfFirst + 1))});

A

// expected output: “The index of the first “dog” from the beginning is 40”

// expected output: “The index of the 2nd “dog” is 52”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q
const paragraph = 'The quick brown fox jumps over the lazy dog. It barked.';
const regex = /[A-Z]/g;
const found = paragraph.match(regex);

console.log(found);

A

// expected output: Array [“T”, “I”]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

const str = ‘The quick brown fox jumps over the lazy dog.’;

const words = str.split(' ');
console.log(words[3]);
const chars = str.split('');
console.log(chars[8]);
const strCopy = str.split();
console.log(strCopy);
A

// expected output: “fox”

// expected output: “k”

// expected output: Array [“The quick brown fox jumps over the lazy dog.”]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

const str = ‘The quick brown fox jumps over the lazy dog.’;

console. log(str.slice(31));
console. log(str.slice(4, 19));
console. log(str.slice(-4));
console. log(str.slice(-9, -5));

A

// expected output: “the lazy dog.”

// expected output: “quick brown fox”

// expected output: “dog.”

// expected output: “lazy”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

const str = ‘Mozilla’;

console. log(str.substring(1, 3));
console. log(str.substring(2));

A

// expected output: “oz”

// expected output: “zilla”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

const str = ‘Mozilla’;

console. log(str.substring(1, 3));
console. log(str.substring(2));

A

// expected output: “oz”

// expected output: “zilla”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly