← Lua Academy

Functions and modules · 26 / 69

Use a supplied module

YOUR TASK

Make this happen

3 steps
  1. require loads a named module. In the academy, modules are explicit in-memory files; missing modules are never fetched from the network. Use the supplied units helper to convert metres to millimetres.

  2. Read the cases in lesson.test.lua, then choose Check solution to see what needs to change.

  3. Update subject.lua until every test passes. Keep the supplied tests unchanged.

Read the starter and tests

subject.lua

local units = require("units")
exports.convert = function(metres: number): number
  return metres
end

lesson.test.lua

local t = require("test")
local subject = require("cococo.subject")

t.it("uses helper", function()
  local s = subject.load()
  t.expect(s.convert(2.5)):eq(2500)
end)