Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

136
Views
How implement logic for increment by 100 on random bids in JS

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!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Several errors to fix

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)

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!