1. Define the HTML structure
Welcome to the Pictogram Game!
Click on the pictograms to play!
2. Create an array of pictogram image URLs and randomly select one to display in the game container
js
const pictograms = ['url1', 'url2', 'url3', 'url4', 'url5'];
const gameContainer = document.getElementById('game-container');
function displayRandomPictogram() {
gameContainer.innerHTML = '';
const randomIndex = Math.floor(Math.random() * pictograms.length);
const pictogramImg = document.createElement('img');
pictogramImg.src=pictograms[randomIndex];
gameContainer.appendChild(pictogramImg);
}
displayRandomPictogram();
3. Add a click event listener to the pictogram and trigger the display of a new random pictogram when clicked
js
pictogramImg.addEventListener('click', function() {
displayRandomPictogram();
});
4. Test the game in a browser to see the first pictogram displayed, and click on it to display new random pictograms each time.
This simple game allows players to interact with pictograms by clicking on them, triggering the display of new random pictograms in the game container. Players can continue clicking to see different pictograms and enjoy the game experience.