Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

After flipping the coin, if one clicks on the coin, it flips and also with the "flip-again" button too. fixed this issue using pointer-events CSS property. #3

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions script.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
let coin = document.getElementById("flip-coin");
let flip = document.getElementById("flip-again");
let toss = Math.floor(Math.random() * 2);

let tossResult = document.getElementById("result");

function flipAgain() {
coin.style.pointerEvents = 'unset';
coin.src = "./images/Flip_coin.png"
tossResult.innerHTML = "";
document.getElementById('flip-again-btn').style.display = "none";
}

coin.addEventListener("click", function () {
coin.addEventListener("click", function (event) {
let toss = Math.floor(Math.random() * 2);
let result;

if (toss == 1) {
result = "Tails";
coin.src = "images/Tails.png"
console.log(toss);
coin.src = "images/Tails.png";
coin.style.pointerEvents = 'none';
} else {
coin.src = "images/Heads.png"
result = "Heads";
coin.style.pointerEvents = 'none';
}

tossResult.innerHTML = `It's ${result}.`
Expand Down