I have a list of names which are constantly looped through and rendered to the h1
tag #randomName
. When the #pickName
button is pressed a random name is selected from the names list (and then removed).
For the purpose of what I'm trying to do this is great, but what I'd love to be able to do is when the #pickName
link is clicked, have the list of names that are looping on screen to slowly slow down (say 3 seconds) and then settle on one of the names (and use this in the alert).
const names = Array('Craig O Mahony', 'Nick Farmer', 'Stuart Lister', 'Lee Rogers', 'Mick O Connor', 'Paul Alexander', 'Robin Allison', 'Neil Bellion', 'Tom / Tim / Mitch', 'Steve Casey', 'Ian Condley', 'Ken Dovey', 'Tony Doyle', 'Dave Field', 'James Field', 'Steve Fuller', 'Jim Harrison', 'Ray Harrison', 'Mick Hennessey', 'John Hodges', 'Shaun Hooper', 'Phil Large', 'Steve Lowe', 'Nevin McDermott', 'Tony McDonnell', 'Steve Nye', 'Paul Read', 'Wayne Rogers', 'Pete Sears', 'Pete Smith', 'Dave Wrafter', 'Rob Wyatt', );
const h1$ = $('#randomName');
var currentMatch = "match";
var counter = 1;
let idx = 0;
setInterval(() => {
h1$.text(names[idx++ % names.length]);
}, 100);
$("#pickName").on('click', function() {
const name = names[Math.floor(Math.random() * names.length)];
alert(name);
names.splice($.inArray(name, names), 1);
//$('#' + name).remove();
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<a class="btn btn-default btn-lg" id="pickName">Draw Player</a>
<h1 style="font-size:4em;padding-top:15px" id="randomName"></h1>