Menu
Coddy logo textTech

Recap - Character Sheet

Part of the Logic & Flow section of Coddy's Lua journey — lesson 4 of 54.

challenge icon

Challenge

Easy

Write a function displayCharacterStats that takes a character table and returns a formatted string displaying all stats.

Use pairs() to iterate through all key-value pairs in the character table and build a string where each line shows a stat name followed by its value in the format key: value. Each stat should be on a separate line.

Parameters:

  • character (table): A dictionary-style table where keys are stat names (strings) and values are stat values (numbers or strings)

Returns: A string with each stat on a separate line. Format:

stat1: value1
stat2: value2
stat3: value3

Try it yourself

function displayCharacterStats(character)
    -- Write code here
end

All lessons in Logic & Flow