Transfer practice · A function has an outer label "Workshop". Return {label="Visitor", outer="Workshop"} by using a separate local visitorLabel rather than replacing label.
v3 · Activity 1 of 1 · scope · locals · 10 min Runs here
Use a familiar idea in a different task. Read the changed requirement before running.
A function has an outer label "Workshop". Return {label="Visitor", outer="Workshop"} by using a separate local visitorLabel rather than replacing label.
Interface: calculate(base, bonus) -> {reward:number, reserve:number}
| Input | Expected |
|---|---|
Separate labels | { label = "Visitor", outer = "Workshop" } |
local total = 100
local function double(value)
local total = value * 2
return total
end
print(double(3))
print(total)
return doubleThe inner total is 6; the outer total remains 100. They are different locals despite the matching name.
New syntax: nested local scope
A local is visible in its lexical scope: the block where it is declared and nested blocks, after the declaration. A function parameter is local to that call.
A new local can shadow an outer name. Assigning without local can instead change an existing outer variable. Read the declaration, not just the identifier spelling.
Independent calculations should create their own temporary values. This also prevents one test call from contaminating a later call.
Select a word or symbol in this authored example. Your editor draft stays unchanged.
reserve 100
calculatebase, bonus
reserve base bonus
reward reserve, reserve reserve
calculateThis 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.