v3 · Activity 2 of 5 · numeric-for · accumulators · 10 min Runs here
for index = 1, count do repeats the body with index 1 through count, including count. end closes the loop.
The loop variable is local to the loop. Use it to create each distinct label, then append that label to a result table.
objectiveLabels(count) returns Step 1 through Step count. Fix the upper bound so the last objective is present. Keep the final return shown in the starter so the checker can call or inspect your result.
Interface: objectiveLabels(count:number) -> {string}
| Input | Expected |
|---|---|
Three objectives3 | { "Step 1", "Step 2", "Step 3" } |
None0 | {} |
local labels = {}
for index = 1, 3 do
table.insert(labels, "Step " .. tostring(index))
end
return labelsThe loop appends Step 1, Step 2 and Step 3 in order.
New syntax: for index = 1, count do, end
return labelslocal function objectiveLabels(count) local labels = {} for index = 1, count do table.insert(labels, "Step " .. tostring(index)) endendreturn objectiveLabelsfor index = 1, count do repeats the body with index 1 through count, including count. end closes the loop.
The loop variable is local to the loop. Use it to create each distinct label, then append that label to a result table.
When count is zero, a positive-step loop from 1 to 0 has no iterations. The empty table is the useful result rather than an invented objective.
Select a word or symbol in this authored example. Your editor draft stays unchanged.
objectiveLabelscount
labels
index 1, count 1
table.insertlabels, index
labels
objectiveLabelsThis is a private experiment copy. It does not replace your answer or complete the activity.
These inputs apply when your scratchpad returns the function described by the activity interface.
Your output will appear here.
Replace this code with the starter? Download your draft to keep a copy.
Your output will appear here.
Sign in with RoCreators to save private progress across devices. Community verification is separate.