0
0
Postmantesting~10 mins

Collection 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 collection variable named 'token' with value 'abc123'.

Postman
pm.collectionVariables.set('[1]', 'abc123');
Drag options to blanks, or click blank then click option'
Atoken
BauthToken
CsessionId
DuserId
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong variable name like 'authToken' instead of 'token'.
Forgetting to put the variable name as a string.
2fill in blank
medium

Complete the code to get the value of the collection variable 'userId'.

Postman
const userId = pm.collectionVariables.get('[1]');
Drag options to blanks, or click blank then click option'
AauthToken
BuserId
CsessionId
Dtoken
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different variable name like 'token' instead of 'userId'.
Not using quotes around the variable name.
3fill in blank
hard

Fix the error in the code to correctly delete the collection variable named 'sessionId'.

Postman
pm.collectionVariables.[1]('sessionId');
Drag options to blanks, or click blank then click option'
Adelete
Bremove
Cunset
Dclear
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'remove' or 'unset' which are not valid methods.
Using 'clear' which clears all variables, not one.
4fill in blank
hard

Fill both blanks to check if the collection variable 'token' exists and then log its value.

Postman
if (pm.collectionVariables.[1]('[2]')) {
  console.log(pm.collectionVariables.get('token'));
}
Drag options to blanks, or click blank then click option'
Ahas
Bexists
Ccontains
Dtoken
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'exists' or 'contains' which are not valid methods.
Using wrong variable name in the second blank.
5fill in blank
hard

Fill all three blanks to update the collection variable 'count' by increasing its value by 1.

Postman
let current = parseInt(pm.collectionVariables.get('[1]')) || 0;
current = current [2] 1;
pm.collectionVariables.set('[3]', current.toString());
Drag options to blanks, or click blank then click option'
Acount
B+
D-
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-' instead of '+' causing decrement.
Using different variable names in get and set.