mardi 1 février 2022

Generating random number from range on click, that isn't the same as previous numbers

I don't really know what I'm doing but been playing with jQuery trying to achieve this. I had the functionality working fine with the exception of occasionally showing the same testimonial twice in a row, which I'm trying to solve. Here is my attempted code which doesn't compute, I'm quite sure it's something obvious that I don't understand! Any help is appreciated.

You can see the intended functionality here in the testimonial footer: https://blue-coast-f4d2bc.webflow.io/contact

     function getNumber(previous) {
  if (previous === undefined) {
      i = Math.floor(Math.random() * 14) + 1;
      return i;
  }
  else {
    while {
      i = previous; 
      i = Math.floor(Math.random() * 14) + 1;
    }
    return i;
  }


var quoteNumb = getNumber();
 $('.footer-testimonial-quote:nth-of-type('+quoteNumb+')').addClass('show');
  
  var footHeight = $('.testimonial-container').height();
$('.testimonial-container').css({'min-height': footHeight  + 'px'});
  $('.testimonial-container').css({'max-height': footHeight  + 'px'});
  
 $(document).ready(function() {
            $(".refresh-button").click(function() {
                $('.footer-testimonial-quote:nth-of-type('+quoteNumb+')').fadeOut(1000, function() {
                $('.footer-testimonial-quote:nth-of-type('+quoteNumb+')').removeClass('show');
                  quoteNumb = getNumber(quoteNumb);
                $('.footer-testimonial-quote:nth-of-type('+quoteNumb+')').addClass('show');
                $('.footer-testimonial-quote:nth-of-type('+quoteNumb+')').fadeIn(1000);
                });
            });
        });



Aucun commentaire:

Enregistrer un commentaire