← Lua Academy

Typed Lua · 30 / 69

Make the return promise true

YOUR TASK

Make this happen

3 steps
  1. A return annotation describes every path through the function. Repair the string returned from a number-producing calculation.

  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

exports.square = function(n: number): number
  return "wrong"
end

lesson.test.lua

local t = require("test")
local subject = require("cococo.subject")
t.it("squares a number", function()
  local s = subject.load()
  t.expect(s.square(4)):eq(16)
end)