Complete the code to set a local variable named 'token' with value 'abc123'.
pm.variables.set('[1]', 'abc123');
The local variable name should be 'token' to store the value locally within the request.
Complete the code to get the value of a local variable named 'sessionId'.
const session = pm.variables.get('[1]');
To retrieve a local variable, use pm.variables.get with the exact variable name, here 'sessionId'.
Fix the error in the code to correctly set a local variable 'userName' with value 'Alice'.
pm.variables.[1]('userName', 'Alice');
To assign a value to a local variable, use pm.variables.set method.
Fill both blanks to check if a local variable 'count' exists and then delete it.
if (pm.variables.[1]('count') !== undefined) { pm.variables.[2]('count'); }
Use pm.variables.get to check if 'count' exists, and pm.variables.unset to delete it.
Fill all three blanks to create a local variable 'status' with value 'active', then retrieve it and check if it equals 'active'.
pm.variables.[1]('status', 'active'); const currentStatus = pm.variables.[2]('status'); if (currentStatus [3] 'active') { console.log('Status is active'); }
First, set the variable with pm.variables.set, then get it with pm.variables.get, and compare using === for equality.