Skip to content
Your progress

Checking your sign-in…

Who's learning?

Each profile keeps its own read lessons, badges, streak, and practice scores on this device.

Lesson 3 of 11

Right out of how many

Show on a big screen

8 min

Text size

The program guessed. The seller knows the real word. How many guesses were right?

Loading lab…

Five kept-back crates: a guess and a real word each.
Step 1 of 4
  1. Five kept-back crates: a guess and a real word each.
  2. Pair 1: full, full. They agree. Tally: 1.
  3. Pairs 2 and 3 agree too. Tally: 3.
  4. Pairs 4 and 5 disagree. Final count: 3 of 5.

The rule

Check the pairs one at a time and count the matches. Here 3 of 5 match.

Walk both lists together. Add one when a pair agrees. Hand back the count. Two lists that agree on nothing give 0.

  • guesses — what the rule said about each kept-back crate.
  • labels — the seller's real word on each one.

The count of right guesses, out of all guesses, is the accuracy. Here it is 3 of 5.

Five kept-back crates: the rule guessed, the seller decided
CrateGuessReal wordAgree?
1fullfullyes
2cutcutyes
3cutcutyes
4cutfullno
5fullcutno

The function agreed(guesses, labels) starts a box, count, at 0. A while loop visits both lists, one pair per turn. Here i is the position, starting at 0. So position 0 is crate 1. An if checks guesses[i] === labels[i]. The sign === asks if two values are the same. On a match, the box adds one. The box goes 1, 2, 3, 3, 3. Then return count gives back the number in the box.

Try the lab to finish this lesson.