I've got a random generator my using arrays and the following string to randomize:
var doelgroepRand = doelgroepArray[Math.floor(Math.random() * doelgroepArray.length)];
/
var divergeerIdee = 'Laat een' + ' ' + doelgroepRand + ' ' + watRand + ' ' + handelingRand
This goes into
$('#something').click( function() {
event.preventDefault();
alert(divergeerIdee); });
});
But to get a new set of random items, you need to refresh the page. I want that, on click, everything is 'resetted' and you get new random items.
What is the string I need?
Simply pack it all in a javascript function. Eg:
function createRandom() {
var doelgroepRand = doelgroepArray[Math.floor(Math.random() * doelgroepArray.length)];
return divergeerIdee = 'Laat een' + ' ' + doelgroepRand + ' ' + watRand + ' ' + handelingRand
}
$('#something').click( function() {
event.preventDefault();
alert(createRandom());
alert(createRandom());
});
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.