41 lines
1.1 KiB
JavaScript
41 lines
1.1 KiB
JavaScript
jQuery(function($) {
|
|
$tAlpha = [
|
|
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
|
|
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'
|
|
];
|
|
|
|
lancerTirage('H', '8');
|
|
|
|
$('.tirer').on('click', function(e) {
|
|
e.stopPropagation();
|
|
const lettre = $('#lettre').val();
|
|
const chiffre = $('#chiffre').val() ?? '8';
|
|
lancerTirage(lettre, chiffre)
|
|
})
|
|
|
|
function lancerTirage(lettre, chiffre) {
|
|
if (lettre) {
|
|
lettre = lettre.toUpperCase();
|
|
$('#lettre').val(lettre);
|
|
}
|
|
|
|
const newLettre = tirage(lettre, 'lettre');
|
|
const newChiffre = tirage(chiffre, 'chiffre');
|
|
|
|
$('.res').html(newLettre + ' ' + newChiffre);
|
|
|
|
}
|
|
|
|
function tirage(i, type) {
|
|
if (type === "chiffre") {
|
|
return aleatoire(1, i)
|
|
}
|
|
const max = $tAlpha.indexOf(i) + 1
|
|
const index = aleatoire(1, max) - 1;
|
|
return $tAlpha[index];
|
|
}
|
|
|
|
function aleatoire(min, max) {
|
|
return Math.floor(Math.random() * max) + min
|
|
};
|
|
});
|