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

Add "Play Again" Button and Improve Alert Handling #55

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
17 changes: 14 additions & 3 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ document.addEventListener('DOMContentLoaded', () => {
if(optionOneId == optionTwoId) {
cards[optionOneId].setAttribute('src', 'images/blank.png')
cards[optionTwoId].setAttribute('src', 'images/blank.png')
alert('You have clicked the same image!')
//alert('You have clicked the same image!')
}
else if (cardsChosen[0] === cardsChosen[1]) {
alert('You found a match')
// alert('You found a match')
cards[optionOneId].setAttribute('src', 'images/white.png')
cards[optionTwoId].setAttribute('src', 'images/white.png')
cards[optionOneId].removeEventListener('click', flipCard)
Expand All @@ -91,13 +91,14 @@ document.addEventListener('DOMContentLoaded', () => {
} else {
cards[optionOneId].setAttribute('src', 'images/blank.png')
cards[optionTwoId].setAttribute('src', 'images/blank.png')
alert('Sorry, try again')
// alert('Sorry, try again')
}
cardsChosen = []
cardsChosenId = []
resultDisplay.textContent = cardsWon.length
if (cardsWon.length === cardArray.length/2) {
resultDisplay.textContent = 'Congratulations! You found them all!'
Again()
}
}

Expand All @@ -114,3 +115,13 @@ document.addEventListener('DOMContentLoaded', () => {

createBoard()
})
function Again(){
let btn=document.createElement("button")
let btntext=document.createTextNode("PLAY AGAIN")
btn.className="btn"
btn.append(btntext)
document.body.appendChild(btn)
btn.onclick=function(){
location.reload()
}
}
25 changes: 25 additions & 0 deletions style.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,29 @@
flex-wrap: wrap;
width: 400px;
height: 300px;
position: absolute;
transform: translate(-50%);
left: 50%;
}
h3{
margin-left: 280px;
}
.btn{
padding: 12px 7px;
background-color: orange;
color: aliceblue;
position: absolute;
transform: translate(-50%);
left: 50%;
font-size: 30px;
font-family: 'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif;
transition:all 0.7s ;
z-index: 5;
border: none;
border-radius: 7px;
}
.btn:hover{
background-color: aliceblue;
color: orange;
outline: 1px orange solid;
}