Skip to content
Game 7 Unit 1 of 6 1 hr learning time

Higher or Lower

One round of the game: show a card, take a guess, reveal the next — and judge it with AND, the operator that tests two things at once.

17% of Hi Lo

Hi-Lo's whole game is one decision, repeated: a number shows, you call higher or lower, the next number reveals whether you were right. Build that single round first — with plain numbers for now — because it hides the one new idea you need: judging a guess with AND.

  10 BORDER 0: PAPER 0: INK 7: CLS
  20 RANDOMIZE
 110 LET a = INT (RND * 13) + 1
 130 CLS
 150 PRINT "Number: "; a
 190 INPUT "Higher or lower (H/L)? "; g$
 200 LET b = INT (RND * 13) + 1
 210 PRINT "Next:   "; b
 220 LET ok = 0
 230 IF g$ = "H" AND b > a THEN LET ok = 1
 240 IF g$ = "L" AND b < a THEN LET ok = 1
 250 IF b = a THEN LET ok = 1
 260 IF ok = 0 THEN PRINT "Wrong!"
 290 IF ok = 1 THEN PRINT "Correct!"
Black ZX Spectrum screen: Number: 1, Next: 12, Correct!
One round: called higher on a 1, the next was 12 — correct.

Two things must be true

A guess is right only when two facts line up: the player said "higher" and the next card is in fact higher. AND is how you test both in a single IF. Line 230 reads IF g$ = "H" AND b > a — true only when the guess was H and b beats a. Line 240 does the mirror for "lower". AND is new, but it reads exactly as it sounds: both sides must hold, or the whole test is false. (Its partner OReither side will do — you will meet when a game needs it.)

Collecting the verdict with a flag

Instead of printing the result inside each test, the program keeps a marker. Line 220 sets ok = 0 (assume wrong); lines 230–250 set ok = 1 if any winning case matches — higher-and-up, lower-and-down, or an equal card, which counts as a free pass. Then lines 260 and 290 act on ok once: "Wrong!" if it is still 0, "Correct!" if it reached 1.

That flag pattern — start with a default, let a few tests flip it, then read it once — keeps the logic tidy when several conditions feed one decision. You will reuse it constantly.

Next: a streak, so one round becomes a run.