โ ๐ Lua World
๐ Race Countdown
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
- Count DOWN with: for i = n, 1, -1 do ... end
- Build the text as you go: result = result .. i .. "... "
- Add "GO!" after the loop.
๐งช Coach checks
- โฏ from 3
- โฏ from 1
- โฏ from 5
Live coach
Getting ready
โโโ
๐ฌ A for loop can count DOWN with a -1 step. Watch it build a string.
function stars(n)
local result = ""
for i = 1, n do
result = result .. "*"
end
return result
end
print(stars(3)) -- ***
print(stars(6)) -- ******
๐ It printed:
Nice โ you saw it work!
๐ Output
๐งฉ Gaps filled! Ready to write it all yourself?