โ ๐ Lua World
๐ Longest Username
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
- #name gives the length of a string.
- Keep a "best so far"; replace it only when a name is strictly longer.
๐งช Coach checks
- โฏ finds Alexander
- โฏ single name
- โฏ tie keeps first
- โฏ longest is last
Live coach
Getting ready
โโโ
๐ฌ #word measures a string. Keep a "best so far" and replace it when beaten.
print(#"Zoe") -- 3
print(#"Alexander") -- 9
function biggestNumber(numbers)
local best = numbers[1]
for _, n in ipairs(numbers) do
if n > best then
best = n
end
end
return best
end
print(biggestNumber({3, 9, 4})) -- 9
๐ It printed:
Nice โ you saw it work!
๐ Output
๐งฉ Gaps filled! Ready to write it all yourself?