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

Devitasari #26

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
102 changes: 102 additions & 0 deletions home.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Inside The Hacktiv Zoo</title>
<script src="https://kit.fontawesome.com/a822615f10.js"></script>
<link rel="stylesheet prefetch" href="https://fonts.googleapis.com/css?family=Bubblegum+Sans" >
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container">
<header>
<h1>Do You Remember Them?</h1>
</header>
<section class="score-panel">
<ul class="stars" style="color: gold">
<li><i class="fa fa-star"></i></li>
<li><i class="fa fa-star"></i></li>
<li><i class="fa fa-star"></i></li>
</ul>
<span class="moves">0</span> <span class="moves1">Move(s)</span>
<div class="timer"></div>
<div class="restart" onclick=startGame()>
<i class="fa fa-repeat"></i>
</div>
</section>
<ul class="collect" id="card-collect">
<li class="card" >
<i class="fa fa-cat"></i>
</li>
<li class="card" >
<i class="fa fa-crow"></i>
</li>
<li class="card" >
<i class="fa fa-dove"></i>
</li>
<li class="card" >
<i class="fa fa-fish"></i>
</li>
<li class="card" >
<i class="fa fa-horse-head"></i>
</li>
<li class="card" >
<i class="fa fa-spider"></i>
</li>
<li class="card" >
<i class="fa fa-dog"></i>
</li>
<li class="card" >
<i class="fa fa-frog"></i>
</li>
<li class="card" >
<i class="fa fa-cat"></i>
</li>
<li class="card" >
<i class="fa fa-crow"></i>
</li>
<li class="card" >
<i class="fa fa-dove"></i>
</li>
<li class="card" >
<i class="fa fa-fish"></i>
</li>
<li class="card" >
<i class="fa fa-horse-head"></i>
</li>
<li class="card" >
<i class="fa fa-spider"></i>
</li>
<li class="card" >
<i class="fa fa-dog"></i>
</li>
<li class="card" >
<i class="fa fa-frog"></i>
</li>
</ul>
<div id="popup1" class="overlay">
<div class="popup">
<h2>🎉 Yeay 🎉</h2>
<a class="close" href=#>x</a>
<div class="content1">
<p>Congratulations <span id=nameUser></span>!!!</p>
I know you remember them so well.
<br>
Thank for helping Devita 😄
</div>
<div class="content2">
<p>You made <span id=finalMove></span> move </p>
<p>in <span id=totalTime> </span></p>
<p>Rating: <span id=starRating></span></p>
</div>
<button id="replay" onclick="replay()">
Play again 😄
</button>
</div>
</div>
</div>
<script src="script.js"></script>
</body>
</html>
Binary file added img/bg2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Hacktiv Zoo's Gate</title>
<script src="https://kit.fontawesome.com/a822615f10.js"></script>
<link rel="stylesheet prefetch" href="https://fonts.googleapis.com/css?family=Bubblegum+Sans" >
<link rel="stylesheet" href="style.css">
</head>
<body>
<header id="header1">
<h1>Welcome to The Hacktiv Zoo</h1>
</header>
<section id="description">
Devita visiting the Hacktiv Zoo with her playgroup friends.
<br>
During her visit, Devita was asked by her teacher to remember what animals she found in the zoo.
<br>
Unfortunately, Devita forgot. Devita needs your help to remember what animals she met at the Hacktiv zoo.
<br>
Do you want to help Devita?
<br>
<a href=".\home.html">with my pleasure 😄</a>
</section>
</body>
</html>
195 changes: 195 additions & 0 deletions script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
var card = document.getElementsByClassName("card");
var cards = [...card];
var collect = document.getElementById("card-collect");
var moves = 0;
var counter = document.querySelector(".moves");
var stars = document.querySelectorAll(".fa-star");
var matchedCard = document.getElementsByClassName("match");
var starsList = document.querySelectorAll(".stars li");
var closeicon = document.querySelector(".close");
var modal = document.getElementById("popup1")
var openedCards = [];
var nameUser1 = ''
//pop up name when loaded or refresh
function init() {
var name = prompt("Welcome to the Hacktiv Zoo. For administration purpose, let us know your name");
if (name === null || name === "" ) {
alert("Sorry, you can't help Devita due to incomplete data");
window.location.href = "index.html"
} else {
nameUser1 = name
alert("Hi " + name + "! We appreciate your kind for helping Devita😄")
startGame();
}
}
document.body.onload = init();
//shuffles cards based on math random
function shuffle(array) {
var currentIndex = array.length
while (currentIndex !== 0) {
var randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex--;
var temporaryValue = array[currentIndex];
array[currentIndex] = array[randomIndex];
array[randomIndex] = temporaryValue;
}
return array;
};
//start new game
function startGame(){
openedCards = [];
cards = shuffle(cards);
for (var i = 0; i < cards.length; i++){
collect.innerHTML = "";
[].forEach.call(cards, function(item) {
collect.appendChild(item);
});
cards[i].classList.remove("show", "open", "match", "disabled");
}
// reset moves
moves = 0;
counter.innerHTML = moves;
// reset rating
for (var i= 0; i < stars.length; i++){
stars[i].style.color = "#FFD700";
stars[i].style.visibility = "visible";
}
//reset timer
second = 0;
minute = 0;
hour = 0;
var timer = document.querySelector(".timer");
timer.innerHTML = "0 mins 0 secs";
clearInterval(interval);
}
//open and show class to display cards
var displayCard = function (){
this.classList.toggle("open");
this.classList.toggle("show");
this.classList.toggle("disabled");
};
//Add opened cards to OpenedCards list and check if cards are match or not
function cardOpen() {
openedCards.push(this);
var len = openedCards.length;
if(len === 2){
moveCounter();
if(openedCards[0].name === openedCards[1].name){
matched();
} else {
unmatched();
}
}
};
//Cards match
function matched(){
openedCards[0].classList.add("match", "disabled");
openedCards[1].classList.add("match", "disabled");
openedCards[0].classList.remove("show", "open", "no-event");
openedCards[1].classList.remove("show", "open", "no-event");
openedCards = [];
}
//Cards don't match
function unmatched(){
openedCards[0].classList.add("unmatched");
openedCards[1].classList.add("unmatched");
disable();
setTimeout(function(){
openedCards[0].classList.remove("show", "open", "no-event","unmatched");
openedCards[1].classList.remove("show", "open", "no-event","unmatched");
enable();
openedCards = [];
},1100);
}
//Disable cards temporarily
function disable(){
Array.prototype.filter.call(cards, function(card){
card.classList.add('disabled');
});
}
//Enable cards and disable matched cards
function enable(){
Array.prototype.filter.call(cards, function(card){
card.classList.remove('disabled');
for(var i = 0; i < matchedCard.length; i++){
matchedCard[i].classList.add("disabled");
}
});
}
//Count player's moves
function moveCounter(){
moves++;
counter.innerHTML = moves;
//start timer on first click
if(moves == 1){
second = 0;
minute = 0;
hour = 0;
startTimer();
}
// setting rates based on moves
if (moves > 8 && moves < 12){
for( i= 0; i < 3; i++){
if(i > 1){
stars[i].style.visibility = "collapse";
}
}
}
else if (moves > 13){
for( i= 0; i < 3; i++){
if(i > 0){
stars[i].style.visibility = "collapse";
}
}
}
}
//Timer
var second = 0, minute = 0; hour = 0;
var timer = document.querySelector(".timer");
var interval;
function startTimer(){
interval = setInterval(function(){
timer.innerHTML = " " + minute+" mins "+second+" secs";
second++;
if(second == 60){
minute++;
second=0;
}
if(minute == 60){
hour++;
minute = 0;
}
},1000);
}
//Greeting card
function congratulations(){
if (matchedCard.length == 16){
clearInterval(interval);
finalTime = timer.innerHTML;
modal.classList.add("show");
var starRating = document.querySelector(".stars").innerHTML;
document.getElementById("nameUser").innerHTML = nameUser1;
document.getElementById("finalMove").innerHTML = moves;
document.getElementById("starRating").innerHTML = starRating;
document.getElementById("totalTime").innerHTML = finalTime;
closeModal();
};
}
function closeModal(){
closeicon.addEventListener("click", function(e){
modal.classList.remove("show");
startGame();
});
}
//To play Again
function replay(){
modal.classList.remove("show");
startGame();
}
// loop to add event listeners to each card
for (var i = 0; i < cards.length; i++){
card = cards[i];
card.addEventListener("click", displayCard);
card.addEventListener("click", cardOpen);
card.addEventListener("click",congratulations);
};
Loading