Thinking in Lua · 5 / 69
Zero is true
YOUR TASK
Make this happen
Only false and nil are falsy in Lua. Zero and the empty string are truthy. Predict the result before changing the expression.
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.isTruthy = function(value) return false end
lesson.test.lua
local t = require("test")
local subject = require("cococo.subject")
t.it("zero is truthy", function()
local s = subject.load()
t.expect(s.isTruthy(0)):eq(true)
end)
t.it("false stays false", function()
local s = subject.load()
t.expect(s.isTruthy(false)):eq(false)
end)
t.it("nil is false", function()
local s = subject.load()
t.expect(s.isTruthy(nil)):eq(false)
end)
t.it("empty text is truthy", function()
local s = subject.load()
t.expect(s.isTruthy("")):eq(true)
end)