Challenge - 5 Problems
String Structure Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateWhat is the output of this string indexing code?
Consider the following JavaScript code that accesses characters in a string by index. What will be printed?
DSA Javascript
const str = "hello"; console.log(str[1]);
Attempts:
2 left
💡 Hint
Remember, string indexing starts at 0.
✗ Incorrect
Strings in JavaScript can be accessed like arrays. The character at index 1 is the second character, which is 'e' in "hello".
❓ Predict Output
intermediateWhat is the output of this string concatenation and length code?
Look at this code that concatenates strings and checks length. What will it print?
DSA Javascript
const s1 = "abc"; const s2 = "def"; const s3 = s1 + s2; console.log(s3.length);
Attempts:
2 left
💡 Hint
Length counts all characters in the combined string.
✗ Incorrect
Concatenating "abc" and "def" results in "abcdef" which has 6 characters.
❓ Predict Output
advancedWhat is the output of this code using string methods?
What will this code print when using string methods to find a character's position?
DSA Javascript
const text = "datastructure"; console.log(text.indexOf('t'));
Attempts:
2 left
💡 Hint
indexOf returns the first position of the character or -1 if not found.
✗ Incorrect
The first 't' in "datastructure" is at index 2 (0-based).
❓ Predict Output
advancedWhat is the output after splitting and joining a string?
This code splits a string into an array and then joins it back. What is printed?
DSA Javascript
const phrase = "a,b,c,d"; const arr = phrase.split(","); const result = arr.join("-"); console.log(result);
Attempts:
2 left
💡 Hint
split breaks the string into parts, join connects them with a new separator.
✗ Incorrect
Splitting by comma creates ["a","b","c","d"]. Joining with '-' creates "a-b-c-d".
🧠 Conceptual
expertWhy are strings considered a data structure and not just text?
Which of the following best explains why strings are considered a data structure in programming?
Attempts:
2 left
💡 Hint
Think about what makes a data structure different from plain text.
✗ Incorrect
Strings are data structures because they organize characters in a sequence and allow operations like accessing characters by position, searching, and slicing.
