xxxxxxxxxx
91
var imagePaths = ["img1.png", "img2.png", "img3.png", "img4.png", "img5.png", "img6.png", "img7.png", "img8.png", "img9.png", "img10.png", "img11.png"];
var imageVotes =
{
"img1.png": 0,
"img2.png": 0,
"img3.png": 0,
"img4.png": 0,
"img5.png": 0,
"img6.png": 0,
"img7.png": 0,
"img8.png": 0,
"img9.png": 0,
"img10.png": 0,
"img11.png": 0
};
var currentImages = [];
var rounds = 0;
var maxRounds = 30;
function setup()
{
noCanvas();
loadImages();
}
function loadImages()
{
if (rounds >= maxRounds)
{
showWinner();
return;
}
var randomIndex1 = floor(random(imagePaths.length));
var randomIndex2 = floor(random(imagePaths.length));
if (randomIndex1 === randomIndex2)
{
randomIndex2 = (randomIndex2 + 1) % imagePaths.length;
}
currentImages = [imagePaths[randomIndex1], imagePaths[randomIndex2]];
document.getElementById('img1').src = currentImages[0];
document.getElementById('img2').src = currentImages[1];
document.getElementById('votes1').innerText = `Cute Counter: ${imageVotes[currentImages[0]]}`;
document.getElementById('votes2').innerText = `Cute Counter: ${imageVotes[currentImages[1]]}`;
}
function vote(selected)
{
let selectedImage = currentImages[selected - 1];
imageVotes[selectedImage]++;
rounds++;
console.log(`Current Votes: ${JSON.stringify(imageVotes)}`);
loadImages();
}
function showWinner()
{
let winner = "";
let maxVotes = 0;
console.log("Image Votes:", imageVotes);
for(let image in imageVotes)
{
if(imageVotes[image] > maxVotes)
{
winner = image;
maxVotes = imageVotes[image];
}
}
console.log("Winner:", winner, "Votes:", maxVotes);
document.getElementById('img1').style.display = 'none';
document.getElementById('img2').style.display = 'none';
var winnerDiv = document.createElement('div');
winnerDiv.innerHTML = `<h2>The Cutest: <img src="${winner}" style="max-width: 300px;"><br>Rank Push: ${maxVotes}</h2>`;
console.log("Winner Div:", winnerDiv);
document.body.appendChild(winnerDiv);
}