fork download
  1. const yesBtn = document.querySelector(".yes-btn");
  2. const noBtn = document.querySelector(".no-btn");
  3. const question = document.querySelector(".question");
  4. const gif = document.querySelector(".gif");
  5.  
  6. // Change text and gif when the Yes button is clicked
  7. yesBtn.addEventListener("click", () => {
  8. question.innerHTML = "Being with you is my biggest blessing. I love you.";
  9. gif.src = "https://m...content-available-to-author-only...y.com/media/v1.Y2lkPTc5MGI3NjExbGNhdXh1b252b2F2b2U4cHRlNGkwMDZsajllaGF1cDJyb2p4NXl2YiZlcD12MV9naWZzX3NlYXJjaCZjdD1n/G6N0pDDgDpLjUvNoyQ/giphy.gif";
  10.  
  11. // Hide the No button
  12. noBtn.style.display = "none";
  13. });
  14.  
  15. // Make the No button move randomly on hover
  16. noBtn.addEventListener("mouseover", () => {
  17. const wrapper = document.querySelector(".wrapper");
  18. const wrapperRect = wrapper.getBoundingClientRect();
  19. const noBtnRect = noBtn.getBoundingClientRect();
  20.  
  21. // Calculate max positions to ensure the button stays within the wrapper
  22. const maxX = wrapperRect.width - noBtnRect.width;
  23. const maxY = wrapperRect.height - noBtnRect.height;
  24.  
  25. // Ensure randomX and randomY are within the wrapper bounds
  26. const randomX = Math.min(Math.floor(Math.random() * maxX), maxX);
  27. const randomY = Math.min(Math.floor(Math.random() * maxY), maxY);
  28.  
  29. noBtn.style.left = randomX + "px";
  30. noBtn.style.top = randomY + "px";
  31. });
Success #stdin #stdout 0.02s 25952KB
stdin
Standard input is empty
stdout
const yesBtn = document.querySelector(".yes-btn");
const noBtn = document.querySelector(".no-btn");
const question = document.querySelector(".question");
const gif = document.querySelector(".gif");

// Change text and gif when the Yes button is clicked
yesBtn.addEventListener("click", () => {
    question.innerHTML = "Being with you is my biggest blessing. I love you.";
    gif.src = "https://m...content-available-to-author-only...y.com/media/v1.Y2lkPTc5MGI3NjExbGNhdXh1b252b2F2b2U4cHRlNGkwMDZsajllaGF1cDJyb2p4NXl2YiZlcD12MV9naWZzX3NlYXJjaCZjdD1n/G6N0pDDgDpLjUvNoyQ/giphy.gif";

    // Hide the No button
    noBtn.style.display = "none";
});

// Make the No button move randomly on hover
noBtn.addEventListener("mouseover", () => {
    const wrapper = document.querySelector(".wrapper");
    const wrapperRect = wrapper.getBoundingClientRect();
    const noBtnRect = noBtn.getBoundingClientRect();

    // Calculate max positions to ensure the button stays within the wrapper
    const maxX = wrapperRect.width - noBtnRect.width;
    const maxY = wrapperRect.height - noBtnRect.height;

    // Ensure randomX and randomY are within the wrapper bounds
    const randomX = Math.min(Math.floor(Math.random() * maxX), maxX);
    const randomY = Math.min(Math.floor(Math.random() * maxY), maxY);

    noBtn.style.left = randomX + "px";
    noBtn.style.top = randomY + "px";
});