Working with data · 16 / 69
Read a named price
YOUR TASK
Make this happen
A map type describes keys and values. Bracket lookup allows a key to come from a variable, unlike dot lookup which names a literal field.
Read the cases in
lesson.test.lua, then choose Check solution to see what needs to change.Update
subject.luauntil every test passes. Keep the supplied tests unchanged.
Read the starter and tests
subject.lua
exports.price = function(prices: { [string]: number }, sku: string): number
return 0
end
lesson.test.lua
local t = require("test")
local subject = require("cococo.subject")
t.it("uses the requested key", function()
local s = subject.load()
t.expect(s.price({ paper = 12, ink = 30 }, "ink")):eq(30)
end)