I am testing Max Bid functionality via Cypress but I need to randomly bid the amount in a way that it will be incremented by 100.
var minval = 100; var maxval = 1000000; var bidAmount = Math.floor(Math.random() * maxval) + minval
The logic is given above is for any random amount. When I implement this logic I get this error: "Bids should be incremented by 100, input was 589" Please share your ideas. Thank you!
The most important is that you have done nothing to ensure the bid amounts are multiples of 100. A simple way to do this is to divide by 100, round to the nearest integer, and then multiply by 100.
Second, it would be good to set minval to a real minimum acceptable value, namely 100.
Third, if you really want the values to go between minval and maxval, you should multiply the Math.random() by (maxval-minval) so that when you add minval, it will be in the range you want.
const minval = 100;
const maxval = 1000000;
const rawBidAmount = Math.floor(Math.random() * (maxval-minval)) + minval
const roundedBidAmount = 100*Math.round(rawBidAmount/100)
console.log(roundedBidAmount)