Skip to main content

Practice · 3 of 5

Number guessing game logic

CHALLENGE
Difficulty: beginner+25 XP

Implement int guesses(int secret, int maxAttempts) that simulates a player who guesses 1, 2, 3, ... in order. Return the attempt number on which the secret is guessed, or -1 if maxAttempts runs out first. guesses(4, 10) returns 4.

Back to lesson: Practice: Practice: Loops