Ages 15–18 · Grades 9–12 · Computer Science
KindForge
Will this program compile — and what does it print?
A red type error isn’t the compiler being difficult — it’s the compiler catching a bug before your code ever runs. Here you read a short program and predict what the compiler will say: will it compile? If it does, what will it print? If it doesn’t, fix it — without changing what it was meant to do. Some fixes compile but do the wrong thing; the goal is the one that does both.
The code is a teaching subset of the Swift language; the programs are original teaching examples. Runs on your device — nothing leaves it.
Loading the compile lab…
How are you feeling?
A case · you decide
Yuki's total that came out as text
Yuki, 16 — writing a small Swift program that adds up the points from a tournament spreadsheet
Yuki reads each score from the spreadsheet as text and writes `let total = score1 + score2`. The scores are "7" and "5". She expects 12. The program prints 75.
Two strings joined with + are glued together, not added. Nothing crashed; the program did exactly what the types said.
Swift would have stopped her if she had tried to add a number to a string. Because both were strings, the code was legal — and wrong.
How should Yuki fix the total?
She now writes `let average = total / 2`. Total is 13. What does the compiler expect her to have noticed?
The tournament table now shows 12 and 6.5. Yuki left a comment above the conversion line: "scores arrive as text."
Who made this?
“In reality, every technology reflects decisions made by designers, companies, and communities, and carries the values and power of those choices.”
- Who benefits from this technology?
- Whose needs are ignored?
Brain break
What next? Pick a door
- More like this StateForge What screen does this state show? LibraryForge What does this helper function return? SyncForge Will both players see the same world?
- A bit harder FilterForge Is your filter fair and accurate? AccessDojo What will a screen reader say? EpsilonForge How much noise protects the people?
- Something different HueForge Which colour pairing reads clearest? FirstJobQuest What will your take-home pay be? QubitForge What will measuring this qubit show?