Generate an actual HTML and JS game using alerts, confirm messages, console.log and…
- User
Generate an actual HTML and JS game using alerts, confirm messages, console.log and others from these descriptions Title: Pop-up Closer Instructions: There are 3 pop-ups that can appear. One is an annoying pop-up, one is a mine that you have to type close or else you get a BSOD, and one is Clippy pop-up, who says random sayings. But if he says the same as the mine pop-up, you had to type it but not get a BSOD. Closing a pop-up will award you 10 points, and double those points for the Clippy one.
- Assistant
// Function to handle the annoying pop-up function handleAnnoyingPopup() { // Show an alert message for the annoying pop-up alert("This is an annoying pop-up!"); // Add 10 points to the score for closing the pop-up score += 10; } // Function to handle the mine pop-up function handleMinePopup() { // Show a confirm message for the mine pop-up let answer = confirm("This is a mine pop-up! Type 'close' to close it, or else you'll get a BSOD!"); // Check if the user typed 'close' if (answer.toLowerCase() === 'close') { // Add 10 points to the score for closing the pop-up score += 10; } else { // Show a console message for the BSOD console.log("BSOD"); } } // Function to handle the Clippy pop-up function handleClippyPopup() { // Create an array of random Clippy phrases let phrases = [ "Do you need any help?", "It looks like you're writing HTML!", "Great job!", "Keep up the good work!", "Double points for closing me!" ]; // Pick a random phrase from the array let randomPhrase = phrases[Math.floor(Math.random() * phrases.length)]; // Show an alert message for the Clippy pop-up with the random phrase alert("This is Clippy! " + randomPhrase); // Double the points for closing the Clippy pop-up score += 20; } // Function to start the game function startGame() { // Loop 3 times to randomly show one of the pop-ups for (let i = 0; i < 3; i++) { // Generate a random number between 1 and 3 let randomNumber = Math.floor(Math.random() * 3) + 1; // Check the random number and call the appropriate function if (randomNumber === 1) { handleAnnoyingPopup(); } else if (randomNumber === 2) { handleMinePopup(); } else { handleClippyPopup(); } } // Show the final score as an alert message alert("Game over! Your score is " + score); } </script> - User
Generate an actual HTML CSS and JS game using alerts, confirm messages, console.log and others from these descriptions Title: Pop-up Closer Instructions: There are 3 pop-ups that can appear. One is an annoying pop-up, one is a mine that you have to type close or else you get a BSOD, and one is Clippy pop-up, who says random sayings. But if he says the same as the mine pop-up, you had to type it but not get a BSOD. Closing a pop-up will award you 10 points, and double those points for the Clippy one.
- Assistant
button { font-size: 24px; padding: 16px; background-color: #5d74b9; color: #fff; border: none; cursor: pointer; transition: all 0.2s ease; } button:hover { background-color: #34495e; } .score { font-size: 36px; margin-top: 32px; } </style><script> // Get the score element let scoreElement = document.querySelector('.score'); // Create a variable to keep track of the score let score = 0; // Function to handle the annoying pop-up function handleAnnoyingPopup() { // Show an alert message for the annoying pop-up alert("This is an annoying pop-up!"); // Add 10 points to the score for closing the pop-up score += 10; } // Function to handle the mine pop-up function handleMinePopup() { // Show a confirm message for the mine pop-up let answer = confirm("This is a mine pop-up! Type 'close' to close it, or else you'll get a BSOD!"); // Check if the user typed 'close' if (answer.toLowerCase() === 'close') { // Add 10 points to the score for closing the pop-up score += 10; } else { // Show a console message for the BSOD console.log("BSOD"); } } // Function to handle the Clippy pop-up function handleClippyPopup() { // Create an array of random Clippy phrases let phrases = [ "Do you need any help?", "It looks like you're writing HTML!", "Great job!", "Keep up the good work!", "Double points for closing me!" ]; // Pick a random phrase from the array let randomPhrase = phrases[Math.floor(Math.random() * phrases.length)]; // Show an alert message for the Clippy pop-up with the random phrase alert("This is Clippy! " + randomPhrase); // Double the points for closing the Clippy pop-up score += 20; } // Function to start the game function startGame() { // Reset the score to 0 score = 0; // Loop 3 times to randomly show one of the pop-ups for (let i = 0; i < 3; i++) { // Generate a random number between 1 and 3 let randomNumber = Math.floor(Math.random() * 3) + 1; // Check the random number and call the appropriate function if (randomNumber === 1) { handleAnnoyingPopup(); } else if (randomNumber === 2) { handleMinePopup(); } else { handleClippyPopup(); } } // Update the score in the HTML updateScore(); } // Function to update the score in the HTML function updateScore() { // Set the text content of the score element to the current score scoreElement.textContent = "Score: " + score; } </script>