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

Colour game pro #6

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
21 changes: 18 additions & 3 deletions index.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,32 @@
padding: 0;
}

#Point {
background-color: lightpink;
display: flex;
position: absolute;
right: 2.5%;
}

#header {
background-color: lightpink;
height: 30vh;
height: 20vh;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}

#container {
#container0 {
background-color: black;
height: 40vh;
display: flex;
justify-content: space-evenly;
align-items: center;
}
#container1 {
background-color: black;
height: 70vh;
height: 40vh;
display: flex;
justify-content: space-evenly;
align-items: center;
Expand All @@ -24,4 +38,5 @@
height: 200px;
width: 200px;
background-color: aliceblue;
border-radius: 25%;
}
168 changes: 163 additions & 5 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,36 @@
<link rel="stylesheet" href="./index.css" />
</head>
<body onload="newGame()">
<div id="Point">
<h3>No. Of Attempts : </h3>
<h3 id="Score">0</h3>
<h3>/4</h3>
</div>
<div id="header">
<h2>The Great</h2>
<h1 id="header-clue">rgb(xxx,xxx,xxx)</h1>
<h2>Guessing Game</h2>
<h1 id="Head1">Guessing Game</h1>
<h2><button onclick="window.location.href=window.location.href">New Game</button></h2>
</div>
<div id="container">
<div id="container0">
<div class="tile" id="1"></div>
<div class="tile" id="2"></div>
<div class="tile" id="3"></div>
</div>
<div id="container1">
<div class="tile" id="4"></div>
<div class="tile" id="5"></div>
<div class="tile" id="6"></div>
</div>

<script>
var t1 = document.getElementById("1");
var t2 = document.getElementById("2");
var t3 = document.getElementById("3");
var t4 = document.getElementById("4");
var t5 = document.getElementById("5");
var t6 = document.getElementById("6");
var x;
var y=0;
var correctColor;

function getRandomColor() {
Expand All @@ -34,32 +50,174 @@ <h2>Guessing Game</h2>
function newGame() {
t1.style.background = getRandomColor();
t2.style.background = getRandomColor();
t3.style.background = getRandomColor();
t4.style.background = getRandomColor();
t5.style.background = getRandomColor();
t6.style.background = getRandomColor();

x = Math.floor(Math.random() * 2 + 1);
x = Math.floor(Math.random() * 6 + 1);

if (x == 1) correctColor = t1.style.background;
else correctColor = t2.style.background;
else if (x==2) correctColor = t2.style.background;
else if (x==3) correctColor = t3.style.background;
else if (x==4) correctColor = t4.style.background;
else if (x==5) correctColor = t5.style.background;
else correctColor = t6.style.background;
/* console.log(x);
console.log(correctColor); */

document.getElementById("header-clue").innerHTML = correctColor;
}

document.getElementById("Score").innerHTML = y;

t1.addEventListener("click", function () {
if (t1.style.background == correctColor) {
t2.style.background = correctColor;
t3.style.background = correctColor;
t4.style.background = correctColor;
t5.style.background = correctColor;
t6.style.background = correctColor;
document.getElementById("Head1").innerHTML = "Congratulations, You did it";
document.getElementById("header").style.background = correctColor;
} else {
t1.style.background = "black";
document.getElementById("Score").innerHTML = y+1;
y=y+1;
if (y==4){
document.getElementById("header-clue").innerHTML = "Game-Over";
t1.style.background = "black";
t2.style.background = "black";
t3.style.background = "black";
t4.style.background = "black";
t5.style.background = "black";
t6.style.background = "black";
}
}
});

t2.addEventListener("click", function () {
if (t2.style.background == correctColor) {
t1.style.background = correctColor;
t3.style.background = correctColor;
t4.style.background = correctColor;
t5.style.background = correctColor;
t6.style.background = correctColor;
document.getElementById("Head1").innerHTML = "Congratulations, You did it";
document.getElementById("header").style.background = correctColor;
} else {
t2.style.background = "black";
document.getElementById("Score").innerHTML = y+1;
y=y+1;
if (y==4){
document.getElementById("header-clue").innerHTML = "Game-Over";
t1.style.background = "black";
t2.style.background = "black";
t3.style.background = "black";
t4.style.background = "black";
t5.style.background = "black";
t6.style.background = "black";
}
}
});

t3.addEventListener("click", function () {
if (t3.style.background == correctColor) {
t2.style.background = correctColor;
t1.style.background = correctColor;
t4.style.background = correctColor;
t5.style.background = correctColor;
t6.style.background = correctColor;
document.getElementById("Head1").innerHTML = "Congratulations, You did it";
document.getElementById("header").style.background = correctColor;
} else {
t3.style.background = "black";
document.getElementById("Score").innerHTML = y+1;
y=y+1;
if (y==4){
document.getElementById("header-clue").innerHTML = "Game-Over";
t1.style.background = "black";
t2.style.background = "black";
t3.style.background = "black";
t4.style.background = "black";
t5.style.background = "black";
t6.style.background = "black";
}
}
});

t4.addEventListener("click", function () {
if (t4.style.background == correctColor) {
t2.style.background = correctColor;
t3.style.background = correctColor;
t1.style.background = correctColor;
t5.style.background = correctColor;
t6.style.background = correctColor;
document.getElementById("Head1").innerHTML = "Congratulations, You did it";
document.getElementById("header").style.background = correctColor;
} else {
t4.style.background = "black";
document.getElementById("Score").innerHTML = y+1;
y=y+1;
if (y==4){
document.getElementById("header-clue").innerHTML = "Game-Over";
t1.style.background = "black";
t2.style.background = "black";
t3.style.background = "black";
t4.style.background = "black";
t5.style.background = "black";
t6.style.background = "black";
}
}
});

t5.addEventListener("click", function () {
if (t5.style.background == correctColor) {
t2.style.background = correctColor;
t3.style.background = correctColor;
t4.style.background = correctColor;
t1.style.background = correctColor;
t6.style.background = correctColor;
document.getElementById("Head1").innerHTML = "Congratulations, You did it";
document.getElementById("header").style.background = correctColor;
} else {
t5.style.background = "black";
document.getElementById("Score").innerHTML = y+1;
y=y+1;
if (y==4){
document.getElementById("header-clue").innerHTML = "Game-Over";
t1.style.background = "black";
t2.style.background = "black";
t3.style.background = "black";
t4.style.background = "black";
t5.style.background = "black";
t6.style.background = "black";
}
}
});

t6.addEventListener("click", function () {
if (t6.style.background == correctColor) {
t2.style.background = correctColor;
t3.style.background = correctColor;
t4.style.background = correctColor;
t5.style.background = correctColor;
t1.style.background = correctColor;
document.getElementById("Head1").innerHTML = "Congratulations, You did it";
document.getElementById("header").style.background = correctColor;
} else {
t6.style.background = "black";
document.getElementById("Score").innerHTML = y+1;
y=y+1;
if (y==4){
document.getElementById("header-clue").innerHTML = "Game-Over";
t1.style.background = "black";
t2.style.background = "black";
t3.style.background = "black";
t4.style.background = "black";
t5.style.background = "black";
t6.style.background = "black";
}
}
});
</script>
Expand Down