I am trying to add event listeners to buttons in my page so that if I want different vocab sets, the game will choose the sets based on the click. I refresh and the page doesn't show my cards anymore, just the buttons.
document.getElementById("vegetables").addEventListener("click", function (){
var wordArray = vegetableVocab;
var imageArray = vegetableImages;
newGame();
})
function shuffleArray(array) {
for (var i = array.length - 1; i > 0; i--) {
var j = Math.floor(Math.random() * (i + 1));
var temp = array[i];
array[i] = array[j];
array[j] = temp;
}
return array;
}
I am trying to add event listeners to buttons in my page so that if I want different vocab sets, the game will choose the sets based on the click. I refresh and the page doesn't show my cards anymore, just the buttons.
var foodVocab = ["pomme", "banane", "orange", "raisins", "avocat", "citron", "prune", "pastèque", "mangue", "poire", "framboise", "fraise", "myrtille", "cerise", "ananas", "abricot"]
var foodImages = ["vocab/food/images/apple.jpg", "vocab/food/images/banana.jpg", "vocab/food/images/orange.png", "vocab/food/images/grapes.jpg", "vocab/food/images/avocado.jpg", "vocab/food/images/lemon.jpg", "vocab/food/images/plum.jpg", "vocab/food/images/watermelon.jpg", "vocab/food/images/mango.png", "vocab/food/images/pear.png", "vocab/food/images/raspberry.png", "vocab/food/images/strawberry.jpg", "vocab/food/images/blueberry.gif", "vocab/food/images/cherry.png", "vocab/food/images/pineapple.jpeg", "vocab/food/images/apricot.jpg"]
document.getElementById("fruits").addEventListener("click", function (){ var wordArray = foodVocab; var imageArray = foodImages; newGame(); })
var vegetableVocab = ["laitue", "céleri", "brocoli", "aubergine", "citrouille", "courgette", "frites", "asperge", "oignon", "ail", "concombre", "piment", "poivron", "champignon", "betterave", "artichaut"]
var vegetableImages = ["vocab/food/images/lettuce.jpg", "vocab/food/images/celery.png", "vocab/food/images/broccoli.png", "vocab/food/images/eggplant.jpg", "vocab/food/images/pumpking.jpeg", "vocab/food/images/zucchini.jpg", "vocab/food/images/frenchfries.gif", "vocab/food/images/asparagus.jpg", "vocab/food/images/onion.png", "vocab/food/images/garlic.jpg", "vocab/food/images/cucumber.jpg", "vocab/food/images/chilipepper.jpeg", "vocab/food/images/bellpepper.png", "vocab/food/images/mushroom.png", "vocab/food/images/beet.jpg", "vocab/food/images/artichoke.gif"]
document.getElementById("vegetables").addEventListener("click", function (){ var wordArray = vegetableVocab; var imageArray = vegetableImages; newGame(); })
function shuffleArray(array) { for (var i = array.length - 1; i > 0; i--) { var j = Math.floor(Math.random() * (i + 1)); var temp = array[i]; array[i] = array[j]; array[j] = temp; } return array; }
function newGame(){ clickCounter = 0; output = []; clickedTiles = []; tileIds = []; tilesFlipped = 0; gameArray = wordArray.concat(imageArray); shuffleArray(gameArray); for(var i = 0; i < gameArray.length; i++) { $("#memoryboard").append('<div id="tile'+i+'" data-card='+gameArray[i]+' class="card">