Challenge - 5 Problems
String Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this string concatenation?
Consider the following MATLAB code that joins two strings. What will be displayed?
MATLAB
str1 = "Hello, "; str2 = "world!"; result = strcat(str1, str2); disp(result);
Attempts:
2 left
💡 Hint
Look at how strcat joins two strings without spaces.
✗ Incorrect
The strcat function joins the two strings exactly, so the output is 'Hello, world!'.
❓ Predict Output
intermediate2:00remaining
What does this code output when extracting a substring?
This MATLAB code extracts part of a string. What is the output?
MATLAB
text = "Programming is fun!"; part = extractBetween(text, 1, 11); disp(part);
Attempts:
2 left
💡 Hint
extractBetween extracts characters from start to end index inclusive.
✗ Incorrect
Characters 1 to 11 in the string are 'Programming'.
❓ Predict Output
advanced2:00remaining
What is the output of this string replacement code?
This MATLAB code replaces a word in a string. What will be displayed?
MATLAB
sentence = "I love apples."; newSentence = replace(sentence, "apples", "oranges"); disp(newSentence);
Attempts:
2 left
💡 Hint
The replace function swaps the old word with the new one.
✗ Incorrect
The word 'apples' is replaced by 'oranges', so the output is 'I love oranges.'.
❓ Predict Output
advanced2:00remaining
What error does this code raise?
What error will this MATLAB code produce?
MATLAB
str = "Hello"; num = 5; result = strcat(str, num); disp(result);
Attempts:
2 left
💡 Hint
strcat expects strings or characters, not numbers.
✗ Incorrect
strcat cannot concatenate a string and a number directly, so it raises an input type error.
🧠 Conceptual
expert2:00remaining
Why are string operations essential in programming?
Which option best explains why string operations are essential in programming?
Attempts:
2 left
💡 Hint
Think about what text data is used for in programs.
✗ Incorrect
String operations let programs work with text, which is everywhere in user input, messages, and data files.