CpuHigherLower/game.js

28 lines
671 B
JavaScript
Raw Normal View History

2023-04-11 13:00:03 +02:00
var cpuList;
var currentCpu;
var nextCpu;
2023-04-11 12:15:56 +02:00
async function main() {
await fetch('./data.json')
.then((response) => response.json())
.then((json) => cpuList = json);
2023-04-11 13:00:03 +02:00
currentCpu = getRandomCpu();
nextCpu = getRandomCpu();
2023-04-11 12:15:56 +02:00
}
function getRandomCpu() {
2023-04-11 13:00:03 +02:00
let randomIndex = getRandomInt(0, cpuList.length)
return {
name: cpuList[randomIndex]["name"].split('@')[0],
score: cpuList[randomIndex]["cpuScore"]
}
2023-04-11 12:15:56 +02:00
}
2023-04-11 13:00:03 +02:00
function getRandomInt(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min) + min); // The maximum is exclusive and the minimum is inclusive
}
2023-04-11 12:15:56 +02:00
main();