function percentage(partialValue, totalValue) { return Math.round((100 * partialValue) / totalValue); } function rand(min, max) { min = Math.ceil(min); max = Math.floor(max); return Math.floor(Math.random() * (max - min + 1)) + min; } const ONE_THOUSAND = 1000; const TEN_THOUSAND = ONE_THOUSAND * 10; const ONE_HUNDRED_THOUSAND = TEN_THOUSAND * 10; const ONE_MILLION = ONE_HUNDRED_THOUSAND * 10; const numberOfDoors = 3; const numberOfTries = 10000; let originalDoorWins = 0; // la porte gagnante let anotherDoorWins = 0; // si on change de porte for (let i = 0; i < numberOfTries; i++) { const myDoor = rand(1, numberOfDoors); // celle que je choisis const correctDoor = rand(1, numberOfDoors); if (myDoor === correctDoor) { originalDoorWins++; } else { anotherDoorWins++; } //console.log({myDoor, correctDoor}); } console.log(`For ${numberOfTries} tries:`); console.log( `${originalDoorWins} wins (${percentage( originalDoorWins, numberOfTries )}%) when keeping the original door.` ); console.log( `${anotherDoorWins} wins (${percentage( anotherDoorWins, numberOfTries )}%) when picking another door.` );