Skip to main content

AP CSA FRQ Guide

2015 FRQ 2: HiddenWord

Write a hint method for a word-guessing game that compares each guessed character with the hidden word.

String Comparison Game22 minute targetStringcharAtcontainsloops

Skills Tested

What this FRQ is really practicing

StringcharAtcontainsloops

Review these topics before attempting the problem.

Starter Approach

How to begin with your own plan

  1. 1Compare each character position in the guess with the hidden word.
  2. 2Use the prompt symbols for exact match, present elsewhere, and not present.

Attempt the problem before opening the solution.

Common Mistakes

Mistakes to watch for while writing

Checking contains before checking exact-position matches.
Comparing strings with == instead of character/string content.
Returning early after only one character.

Self Check

Review questions before you submit

Loops across every character position.

The guess and hidden word have matching lengths in the prompt.

Checks same-position character matches first.

Exact matches take priority over contains checks.

Checks whether a character appears elsewhere in the hidden word.

Use indexOf or contains after the exact-position check fails.

Builds a result string one symbol at a time.

Append the correct symbol for each character position.

Practice Links

Where to go next