0
0
Postmantesting~10 mins

Local variables in Postman - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to set a local variable named 'token' with value 'abc123'.

Postman
pm.variables.set('[1]', 'abc123');
Drag options to blanks, or click blank then click option'
Atoken
BglobalToken
Cenvironment
Dcollection
Attempts:
3 left
💡 Hint
Common Mistakes
Using environment or collection instead of local variable name.
Confusing local variables with global variables.
2fill in blank
medium

Complete the code to get the value of a local variable named 'sessionId'.

Postman
const session = pm.variables.get('[1]');
Drag options to blanks, or click blank then click option'
Atoken
BuserId
Cauth
DsessionId
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong variable names like 'token' or 'auth'.
Trying to get environment or global variables instead of local.
3fill in blank
hard

Fix the error in the code to correctly set a local variable 'userName' with value 'Alice'.

Postman
pm.variables.[1]('userName', 'Alice');
Drag options to blanks, or click blank then click option'
Aunset
Bget
Cset
Dclear
Attempts:
3 left
💡 Hint
Common Mistakes
Using pm.variables.get instead of set for assignment.
Using unset or clear which do not assign values.
4fill in blank
hard

Fill both blanks to check if a local variable 'count' exists and then delete it.

Postman
if (pm.variables.[1]('count') !== undefined) {
  pm.variables.[2]('count');
}
Drag options to blanks, or click blank then click option'
Aget
Bset
Cunset
Dclear
Attempts:
3 left
💡 Hint
Common Mistakes
Using pm.variables.set instead of get for checking existence.
Using clear instead of unset to delete variable.
5fill in blank
hard

Fill all three blanks to create a local variable 'status' with value 'active', then retrieve it and check if it equals 'active'.

Postman
pm.variables.[1]('status', 'active');
const currentStatus = pm.variables.[2]('status');
if (currentStatus [3] 'active') {
  console.log('Status is active');
}
Drag options to blanks, or click blank then click option'
Aset
Bget
C===
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using != instead of === for comparison.
Using get to assign or set to retrieve.