Menu
Coddy logo textTech

Recap: Introduction to Luau

Part of the Introduction To Luau section of Coddy's Lua journey — lesson 5 of 73.

challenge icon

Challenge

Medium

Create a variable named userId with an explicit type annotation of number and assign it the value 12345.

Create a variable named username with an explicit type annotation of string and assign it the value "john_doe".

Suppose your program contains this line, which the type checker rejects:

username = userId -- ✗ type error: number is not a string

Fix it: create a new variable called userIdString of type string that converts userId using tostring(), then assign userIdString to username.

Finally, print userId and username, each on its own line.

Try it yourself

-- Write code here
-- 1) declare userId: number = 12345 and username: string = "john_doe"
-- 2) convert userId with tostring() into userIdString: string
-- 3) assign userIdString to username

-- Print the results
print(userId)
print(username)

All lessons in Introduction To Luau