Four programs that use tables, each with exactly one thing wrong. Two of them crash and two of them do not, and the two that do not are the interesting ones.
Every one of these is a mistake the exam reference sheet would treat differently from Lua. That is not a coincidence.
Three names in the table. This prints nil, then two of them.
local crew = {"Ada", "Bo", "Cy"}
for i = 0, #crew - 1 do print(crew[i])endThis should make a copy before changing anything. It prints The original still starts with 999.
local original = {10, 20, 30}local backup = original
backup[1] = 999
print("The original still starts with " .. original[1])There is no one-line fix for this one, and saying so is part of the answer.
Three scores in the table. This prints all three and then nil.
local scores = {5, 10, 15}
for i = 1, #scores + 1 do print(scores[i])endSay what the exam reference sheet would do here instead, and which of the two behaviors you would rather have.
Four circles expected. It stops with bad argument #3 to 'circle' (number expected, got nil).
local xs = {120, 260, 400, 540}local ys = {180, 320, 240}
function love.draw() for i, x in ipairs(xs) do love.graphics.circle("fill", x, ys[i], 30) endendFor each program, give:
Bug 4 has two correct answers. Give both, and say what each one draws.
Worth 5 points, graded on completion.