header {
background-color: #333;
padding: 20px;
text-align: center;
color: white;
}
main {
max-width: 600px;
margin: 0 auto;
padding: 20px;
background-color: white;
border: 1px solid #ccc;
box-shadow: 0 0 10px #ccc;
text-align: center;
}
button {
background-color: #4CAF50;
color: white;
border: none;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin-top: 20px;
cursor: pointer;
}
span {
font-weight: bold;
}
.alert {
position: fixed;
top: 0;
left: 0;
display: flex;
justify-content: center;
align-items: center;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.8);
z-index: 999;
}
.alert p {
background-color: white;
padding: 20px;
border: 5px solid orange;
font-size: 24px;
text-align: center;
}
.confirm {
position: fixed;
top: 0;
left: 0;
display: flex;
justify-content: center;
align-items: center;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.8);
z-index: 999;
}
.confirm p {
background-color: white;
padding: 20px;
border: 5px solid blue;
font-size: 24px;
text-align: center;
}
.prompt {
position: fixed;
top: 0;
left: 0;
display: flex;
justify-content: center;
align-items: center;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.8);
z-index: 999;
}
.prompt p {
background-color: white;
padding: 20px;
border: 5px solid green;
font-size: 24px;
text-align: center;
}
.bomb {
position: fixed;
top: 0;
left: 0;
display: flex;
justify-content: center;
align-items: center;
width: 100%;
height: 100%;
background-color: rgba(255, 0, 0, 0.8);
z-index: 999;
}
.bomb p {
background-color: white;
padding: 20px;
border: 5px solid red;
font-size: 24px;
text-align: center;
}
```js
function startGame() {
alert("Welcome to Pop-up Closer! Get ready to close some pop-ups.");
playRound();
}
function playRound() {
const popupType = Math.floor(Math.random() * 3);
let popupMessage = "";
let popupPoints = 0;
if (popupType === 0) {
popupMessage = "Annoying Pop-up. Close it!";
popupPoints = 10;
showAlert(popupMessage);
} else if (popupType === 1) {
popupMessage = "Mine Pop-up. Type 'close' to defuse or else you get a BSOD.";
popupPoints = 10;
showConfirm(popupMessage);
} else {
popupMessage = "Clippy Pop-up. Type 'close' to shut me up!";
popupPoints = 20;
showPrompt(popupMessage);
}
const popupInput = document.getElementById("popup-input");
popupInput.focus();
setTimeout(function() {
if (popupType === 0) {
closeAlert();
} else if (popupType === 1) {
if (!popupInput.value || popupInput.value.toLowerCase() !== "close") {
showBomb();
} else {
closeConfirm();
}
} else {
if (!popupInput.value || popupInput.value.toLowerCase() !== "close") {
closePrompt();
} else {
closePrompt();
popupPoints *= 2;
}
}
informPoints(popupPoints);
setTimeout(function() {
playRound();
}, 1000);
}, 3000);
}
function showAlert(message) {
const alertDiv = document.createElement("div");
const alertMessage = document.createElement("p");
alertDiv.classList.add("alert");
alertMessage.innerText = message;
alertDiv.appendChild(alertMessage);
document.body.appendChild(alertDiv);
}
function closeAlert() {
const alertDiv = document.querySelector(".alert");
if (alertDiv) {
alertDiv.parentNode.removeChild(alertDiv);
}
}
function showConfirm(message) {
const confirmDiv = document.createElement("div");
const confirmMessage = document.createElement("p");
const confirmInput = document.createElement("input");
confirmDiv.classList.add("confirm");
confirmMessage.innerText = message;
confirmInput.setAttribute("type", "text");
confirmInput.setAttribute("id", "popup-input");
confirmDiv.appendChild(confirmMessage);
confirmDiv.appendChild(confirmInput);
document.body.appendChild(confirmDiv);
}
function closeConfirm() {
const confirmDiv = document.querySelector(".confirm");
if (confirmDiv) {
confirmDiv.parentNode.removeChild(confirmDiv);
}
}
function showPrompt(message) {
const promptDiv = document.createElement("div");
const promptMessage = document.createElement("p");
const promptInput = document.createElement("input");
promptDiv.classList.add("prompt");
promptMessage.innerText = message;
promptInput.setAttribute("type", "text");
promptInput.setAttribute("id", "popup-input");
promptDiv.appendChild(promptMessage);
promptDiv.appendChild(promptInput);
document.body.appendChild(promptDiv);
}
function closePrompt() {
const promptDiv = document.querySelector(".prompt");
if (promptDiv) {
promptDiv.parentNode.removeChild(promptDiv);
}
}
function showBomb() {
const bombDiv = document.createElement("div");
const bombMessage = document.createElement("p");
bombDiv.classList.add("bomb");
bombMessage.innerText = "BSOD! Game Over.";
bombDiv.appendChild(bombMessage);
document.body.appendChild(bombDiv);
setTimeout(function() {
location.reload();
}, 3000);
}
function informPoints(points) {
console.log(`You earned ${points} points!`);
}