Strings FRQ Practice

Responses receive AI feedback against a rubric after submission. Scores are practice estimates.

Question 1 of 5

Let phrase ← "SCIENCE". substring(s, start, end) is inclusive and 1-based.

(a) What is substring(phrase, 1, 3)? (b) What is substring(phrase, 5, 7)? (c) What off-by-one mistake produces "SCIEN" when someone wants only the first three letters?

Question 2 of 5

Write and evaluate concatenations.

(a) Evaluate "code" + "org". (b) Evaluate substring("codeorg", 5, 7) with inclusive 1-based indexes. (c) Explain how concatenation and substring relate in this example.

Question 3 of 5

Trace:

s ← "PREP"
t ← "ARE"
u ← substring(s, 2, 4) + t
DISPLAY (u)

(a) What is substring(s, 2, 4)? (b) What is displayed? (c) What string results if the end index is mistakenly written as 3 instead of 4 before concatenating t?

Question 4 of 5

A username ruleset builds ids with inclusive substring.

name Desired first three letters
Jordan Jor
Alex Ale

(a) Write the substring call for Jordan. (b) Write the substring call for Alex. (c) Why is substring(name, 1, 2) wrong for both goals?

Question 5 of 5

Define substring as inclusive and 1-based. Let msg ← "HELLO".

(a) List each character with its index. (b) Give substring(msg, 3, 5). (c) If someone wants only "HE" but writes substring(msg, 1, 3), what string do they get, and what error is that?