Skip to content
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
Empty file added Simon Says/Readme.md
Empty file.
72 changes: 72 additions & 0 deletions Simon Says/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
let gameSeq = [];
let userSeq = [];
let start = false;
let level = 0;
let btns = ["red","yellow", "green","purple"];
let startBtn = document.querySelector(".start-btn");
let resetBtn = document.querySelector(".reset-btn");
let h2 = document.querySelector("h2");
let allBtns = document.querySelectorAll(".btn")


startBtn.addEventListener("click", function (event) {
if(start == false){
console.log("Game has been Started");
start = true;

levelUp();
}
});
function gameFlash(btn){
btn.classList.add("flash");
setTimeout(function () {
btn.classList.remove("flash");
},250);
}
function userFlash(btn){
btn.classList.add("user-flash");
setTimeout(function () {
btn.classList.remove("user-flash");
},250);
}
function levelUp(){
userSeq = [];
level++;
h2.innerText = `Level ${level}`;
let randIdx = Math.floor(Math.random() * 3);
let randColr = btns[randIdx];
let randBtn = document.querySelector(`.${randColr}`);
gameSeq.push(randColr);
gameFlash(randBtn);
}
function checkAns(idx){
if(userSeq[idx] === gameSeq[idx]){
if(userSeq.length === gameSeq.length){
setTimeout(levelUp,1000);
}
}
else {
h2.innerHTML = `Game Over ! Your Score is <b> ${level} </b> Please Press Reset Button`;
startBtn.setAttribute("disable", true)
allBtns.setAttribute("disable", true)

}
}
function btnPress(){
let btn = this;
userFlash(btn);
let btnColr = btn.getAttribute("id");
userSeq.push(btnColr);
checkAns(userSeq.length-1);
}

for(btn of allBtns) {
btn.addEventListener("click", btnPress);
}
resetBtn.addEventListener('click', function () {
start = false;
gameSeq = [];
userSeq = [];
level = 0;
levelUp();
});
29 changes: 29 additions & 0 deletions Simon Says/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<title>Simon Says</title>
</head>
<body>
<h1> Simon Says Game</h1>
<h2>Press Start Button To Start The Game</h2>
<button class="start-btn">Start</button>
<button class="reset-btn"> Reset</button>
<div class="btn-container">
<div class="line-one">
<div class="btn red" type="button" id="red"></div>
<div class="btn yellow"type="button" id="yellow"></div>

</div>
<div class="line-two">
<div class="btn green" type="button" id="green"></div>
<div class="btn purple"type="button" id="purple"></div>

</div>
</div>
<script src="app.js"></script>

</body>
</html>
54 changes: 54 additions & 0 deletions Simon Says/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
body{
text-align:center;
background-color: #3b82f6;
}
.btn{
height:150px;
width:200px;
border-radius: 20%;
border: 10px solid black;
margin:1.5rem;
}
.btn-container{
display:flex;
justify-content:center;
}

.red{
background-color:#63aa;
}
.yellow{
background-color:#f99b45;

}
.green{
background-color:#d95980;

}
.purple{
background-color:#819ff9;

}
.start-btn{
height:30px;
width:80px;
text-align:center;
border-radius:50%;
border:1px Solid black;
color:black;

}
.flash{
background-color: white;
}
.user-flash{
background-color:green;
}
.reset-btn{
height:30px;
width:80px;
text-align:center;
border-radius:50%;
border:1px Solid black;
margin-left:50px;
}