Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

138
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda