โ ๐ Lua World
๐ Part Counter
You can practise without a player, but pick a player to score points!
๐ The mission
Today you unlock
Loops inspect each item
Many levels use a loop: start with a simple value, visit each item, update the answer, then return it at the end.
๐ก Hint ladder
- Loop with ipairs and keep a counter starting at 0.
- Only add 1 when the part equals the target.
๐งช Coach checks
- โฏ two bricks
- โฏ none found
- โฏ all match
- โฏ empty world
Live coach
Getting ready
โโโ
๐ฌ A counter that only counts when the if-test passes.
function countBigNumbers(numbers)
local count = 0
for _, n in ipairs(numbers) do
if n > 100 then
count = count + 1
end
end
return count
end
print(countBigNumbers({50, 200, 999, 3})) -- 2
๐ It printed:
Nice โ you saw it work!
๐ Output
๐งฉ Gaps filled! Ready to write it all yourself?