epeat levels (easy, medium, and hard) based on limits
In this script, the levels are repeated based on the specified limits. For example, if the limits are [3, 5, 2], it means 'easy' can be repeated up to 3 times, 'medium' up to 5 times, and 'hard' up to 2 times within the 10 iterations. This script ensures that each level is selected based on its remaining limit until it reaches its maximum allowed occurrences.
by slawe
JavaScript
// Define the levels and their respective limits
const levels = ['easy', 'medium', 'hard'];
const limits = [3, 5, 2]; // limits for each level
// Function to pick a level based on its limits
function pickLevel() {
let random = Math.floor(Math.random() * levels.length);
while (limits[random] <= 0) {
random = Math.floor(Math.random() * levels.length);
}
limits[random]--;
return levels[random];
}
// Define the number of iterations
const iterations = 10; // Change this to any number you want
// Loop to repeat levels
for (let i = 0; i < iterations; i++) {
console.log(pickLevel());
}