Complete the code to generate a random integer between 1 and 100 in Postman.
var randomNumber = [1];The correct way to generate a random integer between 1 and 100 in Postman script is using Math.floor(Math.random() * 100) + 1. This expression creates a random number from 0 to less than 1, multiplies it by 100, floors it to an integer, then adds 1 to shift the range to 1-100.
Complete the code to set a dynamic timestamp variable in Postman.
pm.environment.set('timestamp', [1]);
new Date() directly stores a Date object, not a timestamp number.Date.now() returns the current timestamp in milliseconds since January 1, 1970. This is the preferred way to get a numeric timestamp in Postman scripts.
Fix the error in the code to generate a random email address with a dynamic number in Postman.
var email = `user[1]@example.com`;Using Math.floor(Math.random() * 1000) generates a random integer between 0 and 999, which can be used to create a unique email address. Using Math.random() alone would insert a decimal number, which is less readable.
Fill both blanks to create a dynamic JSON body with a random user ID and current timestamp in Postman.
{
"userId": [1],
"createdAt": [2]
}The userId should be a random integer, so Math.floor(Math.random() * 10000) works well. The createdAt timestamp should be a numeric timestamp, so Date.now() is correct.
Fill all three blanks to generate a dynamic Postman test that checks if the response time is less than 500ms and sets a variable with the current date string.
pm.test('Response time is fast', function () { pm.expect(pm.response.responseTime).to.be.[1](500); }); pm.environment.set('currentDate', [2]); var dateString = [3].toISOString();
The assertion uses below to check if response time is less than 500ms. The current date is set using new Date(). The toISOString() method is called on the same new Date() object to get the date string.