My goal is to create a button that, when clicked, will have a 1.04% probability of navigating to Page A and a 98.96% chance of going to Page B. The challenge I'm facing is in randomizing these results using JavaScript. I am fairly new to this language so any assistance would be greatly appreciated.
--edit-- I am integrating this code into a project on Wix, and below is the complete code I have developed so far. Initially, I used simple whole numbers like 40/60 to ensure functionality, but I am struggling with implementing the smaller percentages such as 1.04 instead of 1.00.
import wixLocation from 'wix-location';
let random = 0, counter40 = 0, counter60 = 0;
$w.onReady(function () {
for (var i = 0; i < 10000000; i++) {
random = Math.floor((Math.random() * 100) + 1);
if (random <= 40) {
counter40++;
} else {
counter60++;
}
}
console.log("counter40: " + counter40.toString());
console.log("counter60: " + counter60.toString());
});
export function button1_click(event) {
random = Math.floor((Math.random() * 100) + 1);
if (random <= 40) {
wixLocation.to("/pageB");
} else {
wixLocation.to("/pageC");
}
}