Hidden style visiblity on card flipping game JavaScript










0















I have a card flipping game in html, css, and js and my last step is to have my cards hidden after the user guesses the right pair. At the moment, after matching the cards, the user is still able to see them. After looking at w3schools, I found a css style called hidden but I would like to implement it in my js. I am having trouble with this and any help would be appreciated. Below is the code snippet.






function myclick() 
var myLink = document.getElementById("mylink");
myLink.onclick = function()
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "script.js";
document.getElementsByTagName("head")[0].appendChild(script);
return false;
;
document.getElementById("mylink").click();





function clock()
var h1 = document.getElementById("clock"),
seconds = 0,
minutes = 0,
hours = 0,
t;

function add()
seconds++;
if (seconds >= 60)
seconds = 0;
minutes++;
if (minutes >= 60)
minutes = 0;
hours++;



h1.textContent =
"Timer:" +
(minutes ? (minutes > 9 ? minutes : "0" + minutes) : "00") +
":" +
(seconds > 9 ? seconds : "0" + seconds);

timer();


function timer()
t = setTimeout(add, 1000);


timer();


var options = document.getElementById("options");
var userInput = options.options[options.selectedIndex].value;

var cover = [
"bg.png",
"bg.png",
"bg.png",
"bg.png",
"bg.png",
"bg.png",
"bg.png",
"bg.png"
];
var dragon_ball = [
// "ultra_instinct_golu.png",
// "ultra_instinct_golu.png",
// "vegeta.jpg",
// "vegeta.jpg",
"picolo.jpg",
"picolo.jpg",
"krillin.png",
"krillin.png",
"gohan.jpg",
"gohan.jpg",
"cell.gif",
"cell.gif"
];
var dragonball_cell = ;
var dragonball_ids = ;
var dragonball_ret = ;
var flipped = 0;
shuffle(dragon_ball);

function startGame()
//Start the clock timer
clock();

var out = "<table>";
out += "<tr>";
var i;

//Create a table based on number of cards
for (i = 0; i < cover.length; i++)
out +=
'<td><div id="tile' +
i +
'" onclick="memory(this,'' +
dragon_ball[i] +
"')">";
out += "<img src=" + dragon_ball[i] + ">";
out += "</div></td>";
if ((i + 1) % 4 === 0)
out += "</tr>";


out += "</table>";
document.getElementById("board").innerHTML = out;

function hide()
var str;
var x;
for (x = 0; x < cover.length; x++)
str = "tile" + x;
document.getElementById(str).innerHTML = "<img src=" + cover[x] + ">";



// setTimeout based on the seconds chosen
if (userInput === "3")
//Timer before it hides the card
setTimeout(hide, 3000);
else if (userInput === "5")
setTimeout(hide, 5000);
else if (userInput === "8")
setTimeout(hide, 8000);



//Shuffle the deck
function shuffle(a)
var j, x, i;
for (i = a.length; i; i--)
j = Math.floor(Math.random() * i);
x = a[i - 1];
a[i - 1] = a[j];
a[j] = x;



function memory(tile, val)
if (dragonball_cell.length < 2)
dragonball_ret.push(tile.innerHTML);
tile.innerHTML = "<img src=" + val + ">";
if (dragonball_cell.length === 0)
dragonball_cell.push(val);
dragonball_ids.push(tile.id);
else if (dragonball_cell.length === 1)
dragonball_cell.push(val);
dragonball_ids.push(tile.id);
if (dragonball_cell[0] === dragonball_cell[1])
flipped += 2;
dragonball_cell = ;
dragonball_ids = ;
dragonball_ret = ;
if (flipped === dragon_ball.length)
alert("Congrats!!! You Win!!!");
location.reload();

else
function turnOver()
document.getElementById(dragonball_ids[0]).innerHTML =
dragonball_ret[0];
document.getElementById(dragonball_ids[1]).innerHTML =
dragonball_ret[1];
dragonball_cell = ;
dragonball_ids = ;
dragonball_ret = ;


setTimeout(turnOver, 700);





startGame();

//Inner timer to count till lose
setInterval(myTimer, 1000);
var count = 0;

function myTimer()
count += 1;
//Give them 2 minutes
if (count === 120)
alert("LOSE!!! 2 Minutes has passed. Reloading game");
location.reload();


#board 
margin: auto;
width: 65%;


.difficulty
margin: auto;
text-align: center;
padding-bottom: 12px;


html
background-color: mediumaquamarine;


h1
text-align: center;


table
background-color: gray;
border: 2px black solid;
padding: 10px;


img
width: 200px;
height: 200px;

<h1>Part C</h1>

<!-- Container for clock -->
<h1 id="clock"><time>Timer:00:00</time></h1>

<div class="difficulty">
<h2>You have 2 minutes</h2>
<h2>How many seconds:</h2>

<form>
<select id="options" title="values">
<!-- <option selected disabled>How many seconds</option> -->
<option value="3">3</option>
<option value="5">5</option>
<option value="8">8</option>
</select>
</form>

<!-- A Button that loads the js file -->
<button type="button" value="Submit" onclick="myclick()">
Submit
<div id="mylink"></div>
</button>
<script type="text/javascript">
</script>
</div>

<div id="cou"></div>
<div id="board"></div>












share|improve this question
























  • you can access style attributes cardelement.style.visibility = "hidden"; or you could use jquery $("cardlement-selector").hide();

    – gp.
    Nov 12 '18 at 14:36











  • where could i put the .style.visiblity = "hidden" in the code?

    – theMan23
    Nov 12 '18 at 14:39











  • As you mentioned that after matching the cards you want to hide those cards, so simply put the above code where you check if the cards are matching.

    – Nik
    Nov 12 '18 at 14:54











  • document.getElementById("tile").style.visibility = "hidden"; I tried this after checking if they are === but no luck.

    – theMan23
    Nov 12 '18 at 15:00















0















I have a card flipping game in html, css, and js and my last step is to have my cards hidden after the user guesses the right pair. At the moment, after matching the cards, the user is still able to see them. After looking at w3schools, I found a css style called hidden but I would like to implement it in my js. I am having trouble with this and any help would be appreciated. Below is the code snippet.






function myclick() 
var myLink = document.getElementById("mylink");
myLink.onclick = function()
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "script.js";
document.getElementsByTagName("head")[0].appendChild(script);
return false;
;
document.getElementById("mylink").click();





function clock()
var h1 = document.getElementById("clock"),
seconds = 0,
minutes = 0,
hours = 0,
t;

function add()
seconds++;
if (seconds >= 60)
seconds = 0;
minutes++;
if (minutes >= 60)
minutes = 0;
hours++;



h1.textContent =
"Timer:" +
(minutes ? (minutes > 9 ? minutes : "0" + minutes) : "00") +
":" +
(seconds > 9 ? seconds : "0" + seconds);

timer();


function timer()
t = setTimeout(add, 1000);


timer();


var options = document.getElementById("options");
var userInput = options.options[options.selectedIndex].value;

var cover = [
"bg.png",
"bg.png",
"bg.png",
"bg.png",
"bg.png",
"bg.png",
"bg.png",
"bg.png"
];
var dragon_ball = [
// "ultra_instinct_golu.png",
// "ultra_instinct_golu.png",
// "vegeta.jpg",
// "vegeta.jpg",
"picolo.jpg",
"picolo.jpg",
"krillin.png",
"krillin.png",
"gohan.jpg",
"gohan.jpg",
"cell.gif",
"cell.gif"
];
var dragonball_cell = ;
var dragonball_ids = ;
var dragonball_ret = ;
var flipped = 0;
shuffle(dragon_ball);

function startGame()
//Start the clock timer
clock();

var out = "<table>";
out += "<tr>";
var i;

//Create a table based on number of cards
for (i = 0; i < cover.length; i++)
out +=
'<td><div id="tile' +
i +
'" onclick="memory(this,'' +
dragon_ball[i] +
"')">";
out += "<img src=" + dragon_ball[i] + ">";
out += "</div></td>";
if ((i + 1) % 4 === 0)
out += "</tr>";


out += "</table>";
document.getElementById("board").innerHTML = out;

function hide()
var str;
var x;
for (x = 0; x < cover.length; x++)
str = "tile" + x;
document.getElementById(str).innerHTML = "<img src=" + cover[x] + ">";



// setTimeout based on the seconds chosen
if (userInput === "3")
//Timer before it hides the card
setTimeout(hide, 3000);
else if (userInput === "5")
setTimeout(hide, 5000);
else if (userInput === "8")
setTimeout(hide, 8000);



//Shuffle the deck
function shuffle(a)
var j, x, i;
for (i = a.length; i; i--)
j = Math.floor(Math.random() * i);
x = a[i - 1];
a[i - 1] = a[j];
a[j] = x;



function memory(tile, val)
if (dragonball_cell.length < 2)
dragonball_ret.push(tile.innerHTML);
tile.innerHTML = "<img src=" + val + ">";
if (dragonball_cell.length === 0)
dragonball_cell.push(val);
dragonball_ids.push(tile.id);
else if (dragonball_cell.length === 1)
dragonball_cell.push(val);
dragonball_ids.push(tile.id);
if (dragonball_cell[0] === dragonball_cell[1])
flipped += 2;
dragonball_cell = ;
dragonball_ids = ;
dragonball_ret = ;
if (flipped === dragon_ball.length)
alert("Congrats!!! You Win!!!");
location.reload();

else
function turnOver()
document.getElementById(dragonball_ids[0]).innerHTML =
dragonball_ret[0];
document.getElementById(dragonball_ids[1]).innerHTML =
dragonball_ret[1];
dragonball_cell = ;
dragonball_ids = ;
dragonball_ret = ;


setTimeout(turnOver, 700);





startGame();

//Inner timer to count till lose
setInterval(myTimer, 1000);
var count = 0;

function myTimer()
count += 1;
//Give them 2 minutes
if (count === 120)
alert("LOSE!!! 2 Minutes has passed. Reloading game");
location.reload();


#board 
margin: auto;
width: 65%;


.difficulty
margin: auto;
text-align: center;
padding-bottom: 12px;


html
background-color: mediumaquamarine;


h1
text-align: center;


table
background-color: gray;
border: 2px black solid;
padding: 10px;


img
width: 200px;
height: 200px;

<h1>Part C</h1>

<!-- Container for clock -->
<h1 id="clock"><time>Timer:00:00</time></h1>

<div class="difficulty">
<h2>You have 2 minutes</h2>
<h2>How many seconds:</h2>

<form>
<select id="options" title="values">
<!-- <option selected disabled>How many seconds</option> -->
<option value="3">3</option>
<option value="5">5</option>
<option value="8">8</option>
</select>
</form>

<!-- A Button that loads the js file -->
<button type="button" value="Submit" onclick="myclick()">
Submit
<div id="mylink"></div>
</button>
<script type="text/javascript">
</script>
</div>

<div id="cou"></div>
<div id="board"></div>












share|improve this question
























  • you can access style attributes cardelement.style.visibility = "hidden"; or you could use jquery $("cardlement-selector").hide();

    – gp.
    Nov 12 '18 at 14:36











  • where could i put the .style.visiblity = "hidden" in the code?

    – theMan23
    Nov 12 '18 at 14:39











  • As you mentioned that after matching the cards you want to hide those cards, so simply put the above code where you check if the cards are matching.

    – Nik
    Nov 12 '18 at 14:54











  • document.getElementById("tile").style.visibility = "hidden"; I tried this after checking if they are === but no luck.

    – theMan23
    Nov 12 '18 at 15:00













0












0








0








I have a card flipping game in html, css, and js and my last step is to have my cards hidden after the user guesses the right pair. At the moment, after matching the cards, the user is still able to see them. After looking at w3schools, I found a css style called hidden but I would like to implement it in my js. I am having trouble with this and any help would be appreciated. Below is the code snippet.






function myclick() 
var myLink = document.getElementById("mylink");
myLink.onclick = function()
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "script.js";
document.getElementsByTagName("head")[0].appendChild(script);
return false;
;
document.getElementById("mylink").click();





function clock()
var h1 = document.getElementById("clock"),
seconds = 0,
minutes = 0,
hours = 0,
t;

function add()
seconds++;
if (seconds >= 60)
seconds = 0;
minutes++;
if (minutes >= 60)
minutes = 0;
hours++;



h1.textContent =
"Timer:" +
(minutes ? (minutes > 9 ? minutes : "0" + minutes) : "00") +
":" +
(seconds > 9 ? seconds : "0" + seconds);

timer();


function timer()
t = setTimeout(add, 1000);


timer();


var options = document.getElementById("options");
var userInput = options.options[options.selectedIndex].value;

var cover = [
"bg.png",
"bg.png",
"bg.png",
"bg.png",
"bg.png",
"bg.png",
"bg.png",
"bg.png"
];
var dragon_ball = [
// "ultra_instinct_golu.png",
// "ultra_instinct_golu.png",
// "vegeta.jpg",
// "vegeta.jpg",
"picolo.jpg",
"picolo.jpg",
"krillin.png",
"krillin.png",
"gohan.jpg",
"gohan.jpg",
"cell.gif",
"cell.gif"
];
var dragonball_cell = ;
var dragonball_ids = ;
var dragonball_ret = ;
var flipped = 0;
shuffle(dragon_ball);

function startGame()
//Start the clock timer
clock();

var out = "<table>";
out += "<tr>";
var i;

//Create a table based on number of cards
for (i = 0; i < cover.length; i++)
out +=
'<td><div id="tile' +
i +
'" onclick="memory(this,'' +
dragon_ball[i] +
"')">";
out += "<img src=" + dragon_ball[i] + ">";
out += "</div></td>";
if ((i + 1) % 4 === 0)
out += "</tr>";


out += "</table>";
document.getElementById("board").innerHTML = out;

function hide()
var str;
var x;
for (x = 0; x < cover.length; x++)
str = "tile" + x;
document.getElementById(str).innerHTML = "<img src=" + cover[x] + ">";



// setTimeout based on the seconds chosen
if (userInput === "3")
//Timer before it hides the card
setTimeout(hide, 3000);
else if (userInput === "5")
setTimeout(hide, 5000);
else if (userInput === "8")
setTimeout(hide, 8000);



//Shuffle the deck
function shuffle(a)
var j, x, i;
for (i = a.length; i; i--)
j = Math.floor(Math.random() * i);
x = a[i - 1];
a[i - 1] = a[j];
a[j] = x;



function memory(tile, val)
if (dragonball_cell.length < 2)
dragonball_ret.push(tile.innerHTML);
tile.innerHTML = "<img src=" + val + ">";
if (dragonball_cell.length === 0)
dragonball_cell.push(val);
dragonball_ids.push(tile.id);
else if (dragonball_cell.length === 1)
dragonball_cell.push(val);
dragonball_ids.push(tile.id);
if (dragonball_cell[0] === dragonball_cell[1])
flipped += 2;
dragonball_cell = ;
dragonball_ids = ;
dragonball_ret = ;
if (flipped === dragon_ball.length)
alert("Congrats!!! You Win!!!");
location.reload();

else
function turnOver()
document.getElementById(dragonball_ids[0]).innerHTML =
dragonball_ret[0];
document.getElementById(dragonball_ids[1]).innerHTML =
dragonball_ret[1];
dragonball_cell = ;
dragonball_ids = ;
dragonball_ret = ;


setTimeout(turnOver, 700);





startGame();

//Inner timer to count till lose
setInterval(myTimer, 1000);
var count = 0;

function myTimer()
count += 1;
//Give them 2 minutes
if (count === 120)
alert("LOSE!!! 2 Minutes has passed. Reloading game");
location.reload();


#board 
margin: auto;
width: 65%;


.difficulty
margin: auto;
text-align: center;
padding-bottom: 12px;


html
background-color: mediumaquamarine;


h1
text-align: center;


table
background-color: gray;
border: 2px black solid;
padding: 10px;


img
width: 200px;
height: 200px;

<h1>Part C</h1>

<!-- Container for clock -->
<h1 id="clock"><time>Timer:00:00</time></h1>

<div class="difficulty">
<h2>You have 2 minutes</h2>
<h2>How many seconds:</h2>

<form>
<select id="options" title="values">
<!-- <option selected disabled>How many seconds</option> -->
<option value="3">3</option>
<option value="5">5</option>
<option value="8">8</option>
</select>
</form>

<!-- A Button that loads the js file -->
<button type="button" value="Submit" onclick="myclick()">
Submit
<div id="mylink"></div>
</button>
<script type="text/javascript">
</script>
</div>

<div id="cou"></div>
<div id="board"></div>












share|improve this question
















I have a card flipping game in html, css, and js and my last step is to have my cards hidden after the user guesses the right pair. At the moment, after matching the cards, the user is still able to see them. After looking at w3schools, I found a css style called hidden but I would like to implement it in my js. I am having trouble with this and any help would be appreciated. Below is the code snippet.






function myclick() 
var myLink = document.getElementById("mylink");
myLink.onclick = function()
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "script.js";
document.getElementsByTagName("head")[0].appendChild(script);
return false;
;
document.getElementById("mylink").click();





function clock()
var h1 = document.getElementById("clock"),
seconds = 0,
minutes = 0,
hours = 0,
t;

function add()
seconds++;
if (seconds >= 60)
seconds = 0;
minutes++;
if (minutes >= 60)
minutes = 0;
hours++;



h1.textContent =
"Timer:" +
(minutes ? (minutes > 9 ? minutes : "0" + minutes) : "00") +
":" +
(seconds > 9 ? seconds : "0" + seconds);

timer();


function timer()
t = setTimeout(add, 1000);


timer();


var options = document.getElementById("options");
var userInput = options.options[options.selectedIndex].value;

var cover = [
"bg.png",
"bg.png",
"bg.png",
"bg.png",
"bg.png",
"bg.png",
"bg.png",
"bg.png"
];
var dragon_ball = [
// "ultra_instinct_golu.png",
// "ultra_instinct_golu.png",
// "vegeta.jpg",
// "vegeta.jpg",
"picolo.jpg",
"picolo.jpg",
"krillin.png",
"krillin.png",
"gohan.jpg",
"gohan.jpg",
"cell.gif",
"cell.gif"
];
var dragonball_cell = ;
var dragonball_ids = ;
var dragonball_ret = ;
var flipped = 0;
shuffle(dragon_ball);

function startGame()
//Start the clock timer
clock();

var out = "<table>";
out += "<tr>";
var i;

//Create a table based on number of cards
for (i = 0; i < cover.length; i++)
out +=
'<td><div id="tile' +
i +
'" onclick="memory(this,'' +
dragon_ball[i] +
"')">";
out += "<img src=" + dragon_ball[i] + ">";
out += "</div></td>";
if ((i + 1) % 4 === 0)
out += "</tr>";


out += "</table>";
document.getElementById("board").innerHTML = out;

function hide()
var str;
var x;
for (x = 0; x < cover.length; x++)
str = "tile" + x;
document.getElementById(str).innerHTML = "<img src=" + cover[x] + ">";



// setTimeout based on the seconds chosen
if (userInput === "3")
//Timer before it hides the card
setTimeout(hide, 3000);
else if (userInput === "5")
setTimeout(hide, 5000);
else if (userInput === "8")
setTimeout(hide, 8000);



//Shuffle the deck
function shuffle(a)
var j, x, i;
for (i = a.length; i; i--)
j = Math.floor(Math.random() * i);
x = a[i - 1];
a[i - 1] = a[j];
a[j] = x;



function memory(tile, val)
if (dragonball_cell.length < 2)
dragonball_ret.push(tile.innerHTML);
tile.innerHTML = "<img src=" + val + ">";
if (dragonball_cell.length === 0)
dragonball_cell.push(val);
dragonball_ids.push(tile.id);
else if (dragonball_cell.length === 1)
dragonball_cell.push(val);
dragonball_ids.push(tile.id);
if (dragonball_cell[0] === dragonball_cell[1])
flipped += 2;
dragonball_cell = ;
dragonball_ids = ;
dragonball_ret = ;
if (flipped === dragon_ball.length)
alert("Congrats!!! You Win!!!");
location.reload();

else
function turnOver()
document.getElementById(dragonball_ids[0]).innerHTML =
dragonball_ret[0];
document.getElementById(dragonball_ids[1]).innerHTML =
dragonball_ret[1];
dragonball_cell = ;
dragonball_ids = ;
dragonball_ret = ;


setTimeout(turnOver, 700);





startGame();

//Inner timer to count till lose
setInterval(myTimer, 1000);
var count = 0;

function myTimer()
count += 1;
//Give them 2 minutes
if (count === 120)
alert("LOSE!!! 2 Minutes has passed. Reloading game");
location.reload();


#board 
margin: auto;
width: 65%;


.difficulty
margin: auto;
text-align: center;
padding-bottom: 12px;


html
background-color: mediumaquamarine;


h1
text-align: center;


table
background-color: gray;
border: 2px black solid;
padding: 10px;


img
width: 200px;
height: 200px;

<h1>Part C</h1>

<!-- Container for clock -->
<h1 id="clock"><time>Timer:00:00</time></h1>

<div class="difficulty">
<h2>You have 2 minutes</h2>
<h2>How many seconds:</h2>

<form>
<select id="options" title="values">
<!-- <option selected disabled>How many seconds</option> -->
<option value="3">3</option>
<option value="5">5</option>
<option value="8">8</option>
</select>
</form>

<!-- A Button that loads the js file -->
<button type="button" value="Submit" onclick="myclick()">
Submit
<div id="mylink"></div>
</button>
<script type="text/javascript">
</script>
</div>

<div id="cou"></div>
<div id="board"></div>








function myclick() 
var myLink = document.getElementById("mylink");
myLink.onclick = function()
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "script.js";
document.getElementsByTagName("head")[0].appendChild(script);
return false;
;
document.getElementById("mylink").click();





function clock()
var h1 = document.getElementById("clock"),
seconds = 0,
minutes = 0,
hours = 0,
t;

function add()
seconds++;
if (seconds >= 60)
seconds = 0;
minutes++;
if (minutes >= 60)
minutes = 0;
hours++;



h1.textContent =
"Timer:" +
(minutes ? (minutes > 9 ? minutes : "0" + minutes) : "00") +
":" +
(seconds > 9 ? seconds : "0" + seconds);

timer();


function timer()
t = setTimeout(add, 1000);


timer();


var options = document.getElementById("options");
var userInput = options.options[options.selectedIndex].value;

var cover = [
"bg.png",
"bg.png",
"bg.png",
"bg.png",
"bg.png",
"bg.png",
"bg.png",
"bg.png"
];
var dragon_ball = [
// "ultra_instinct_golu.png",
// "ultra_instinct_golu.png",
// "vegeta.jpg",
// "vegeta.jpg",
"picolo.jpg",
"picolo.jpg",
"krillin.png",
"krillin.png",
"gohan.jpg",
"gohan.jpg",
"cell.gif",
"cell.gif"
];
var dragonball_cell = ;
var dragonball_ids = ;
var dragonball_ret = ;
var flipped = 0;
shuffle(dragon_ball);

function startGame()
//Start the clock timer
clock();

var out = "<table>";
out += "<tr>";
var i;

//Create a table based on number of cards
for (i = 0; i < cover.length; i++)
out +=
'<td><div id="tile' +
i +
'" onclick="memory(this,'' +
dragon_ball[i] +
"')">";
out += "<img src=" + dragon_ball[i] + ">";
out += "</div></td>";
if ((i + 1) % 4 === 0)
out += "</tr>";


out += "</table>";
document.getElementById("board").innerHTML = out;

function hide()
var str;
var x;
for (x = 0; x < cover.length; x++)
str = "tile" + x;
document.getElementById(str).innerHTML = "<img src=" + cover[x] + ">";



// setTimeout based on the seconds chosen
if (userInput === "3")
//Timer before it hides the card
setTimeout(hide, 3000);
else if (userInput === "5")
setTimeout(hide, 5000);
else if (userInput === "8")
setTimeout(hide, 8000);



//Shuffle the deck
function shuffle(a)
var j, x, i;
for (i = a.length; i; i--)
j = Math.floor(Math.random() * i);
x = a[i - 1];
a[i - 1] = a[j];
a[j] = x;



function memory(tile, val)
if (dragonball_cell.length < 2)
dragonball_ret.push(tile.innerHTML);
tile.innerHTML = "<img src=" + val + ">";
if (dragonball_cell.length === 0)
dragonball_cell.push(val);
dragonball_ids.push(tile.id);
else if (dragonball_cell.length === 1)
dragonball_cell.push(val);
dragonball_ids.push(tile.id);
if (dragonball_cell[0] === dragonball_cell[1])
flipped += 2;
dragonball_cell = ;
dragonball_ids = ;
dragonball_ret = ;
if (flipped === dragon_ball.length)
alert("Congrats!!! You Win!!!");
location.reload();

else
function turnOver()
document.getElementById(dragonball_ids[0]).innerHTML =
dragonball_ret[0];
document.getElementById(dragonball_ids[1]).innerHTML =
dragonball_ret[1];
dragonball_cell = ;
dragonball_ids = ;
dragonball_ret = ;


setTimeout(turnOver, 700);





startGame();

//Inner timer to count till lose
setInterval(myTimer, 1000);
var count = 0;

function myTimer()
count += 1;
//Give them 2 minutes
if (count === 120)
alert("LOSE!!! 2 Minutes has passed. Reloading game");
location.reload();


#board 
margin: auto;
width: 65%;


.difficulty
margin: auto;
text-align: center;
padding-bottom: 12px;


html
background-color: mediumaquamarine;


h1
text-align: center;


table
background-color: gray;
border: 2px black solid;
padding: 10px;


img
width: 200px;
height: 200px;

<h1>Part C</h1>

<!-- Container for clock -->
<h1 id="clock"><time>Timer:00:00</time></h1>

<div class="difficulty">
<h2>You have 2 minutes</h2>
<h2>How many seconds:</h2>

<form>
<select id="options" title="values">
<!-- <option selected disabled>How many seconds</option> -->
<option value="3">3</option>
<option value="5">5</option>
<option value="8">8</option>
</select>
</form>

<!-- A Button that loads the js file -->
<button type="button" value="Submit" onclick="myclick()">
Submit
<div id="mylink"></div>
</button>
<script type="text/javascript">
</script>
</div>

<div id="cou"></div>
<div id="board"></div>





function myclick() 
var myLink = document.getElementById("mylink");
myLink.onclick = function()
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "script.js";
document.getElementsByTagName("head")[0].appendChild(script);
return false;
;
document.getElementById("mylink").click();





function clock()
var h1 = document.getElementById("clock"),
seconds = 0,
minutes = 0,
hours = 0,
t;

function add()
seconds++;
if (seconds >= 60)
seconds = 0;
minutes++;
if (minutes >= 60)
minutes = 0;
hours++;



h1.textContent =
"Timer:" +
(minutes ? (minutes > 9 ? minutes : "0" + minutes) : "00") +
":" +
(seconds > 9 ? seconds : "0" + seconds);

timer();


function timer()
t = setTimeout(add, 1000);


timer();


var options = document.getElementById("options");
var userInput = options.options[options.selectedIndex].value;

var cover = [
"bg.png",
"bg.png",
"bg.png",
"bg.png",
"bg.png",
"bg.png",
"bg.png",
"bg.png"
];
var dragon_ball = [
// "ultra_instinct_golu.png",
// "ultra_instinct_golu.png",
// "vegeta.jpg",
// "vegeta.jpg",
"picolo.jpg",
"picolo.jpg",
"krillin.png",
"krillin.png",
"gohan.jpg",
"gohan.jpg",
"cell.gif",
"cell.gif"
];
var dragonball_cell = ;
var dragonball_ids = ;
var dragonball_ret = ;
var flipped = 0;
shuffle(dragon_ball);

function startGame()
//Start the clock timer
clock();

var out = "<table>";
out += "<tr>";
var i;

//Create a table based on number of cards
for (i = 0; i < cover.length; i++)
out +=
'<td><div id="tile' +
i +
'" onclick="memory(this,'' +
dragon_ball[i] +
"')">";
out += "<img src=" + dragon_ball[i] + ">";
out += "</div></td>";
if ((i + 1) % 4 === 0)
out += "</tr>";


out += "</table>";
document.getElementById("board").innerHTML = out;

function hide()
var str;
var x;
for (x = 0; x < cover.length; x++)
str = "tile" + x;
document.getElementById(str).innerHTML = "<img src=" + cover[x] + ">";



// setTimeout based on the seconds chosen
if (userInput === "3")
//Timer before it hides the card
setTimeout(hide, 3000);
else if (userInput === "5")
setTimeout(hide, 5000);
else if (userInput === "8")
setTimeout(hide, 8000);



//Shuffle the deck
function shuffle(a)
var j, x, i;
for (i = a.length; i; i--)
j = Math.floor(Math.random() * i);
x = a[i - 1];
a[i - 1] = a[j];
a[j] = x;



function memory(tile, val)
if (dragonball_cell.length < 2)
dragonball_ret.push(tile.innerHTML);
tile.innerHTML = "<img src=" + val + ">";
if (dragonball_cell.length === 0)
dragonball_cell.push(val);
dragonball_ids.push(tile.id);
else if (dragonball_cell.length === 1)
dragonball_cell.push(val);
dragonball_ids.push(tile.id);
if (dragonball_cell[0] === dragonball_cell[1])
flipped += 2;
dragonball_cell = ;
dragonball_ids = ;
dragonball_ret = ;
if (flipped === dragon_ball.length)
alert("Congrats!!! You Win!!!");
location.reload();

else
function turnOver()
document.getElementById(dragonball_ids[0]).innerHTML =
dragonball_ret[0];
document.getElementById(dragonball_ids[1]).innerHTML =
dragonball_ret[1];
dragonball_cell = ;
dragonball_ids = ;
dragonball_ret = ;


setTimeout(turnOver, 700);





startGame();

//Inner timer to count till lose
setInterval(myTimer, 1000);
var count = 0;

function myTimer()
count += 1;
//Give them 2 minutes
if (count === 120)
alert("LOSE!!! 2 Minutes has passed. Reloading game");
location.reload();


#board 
margin: auto;
width: 65%;


.difficulty
margin: auto;
text-align: center;
padding-bottom: 12px;


html
background-color: mediumaquamarine;


h1
text-align: center;


table
background-color: gray;
border: 2px black solid;
padding: 10px;


img
width: 200px;
height: 200px;

<h1>Part C</h1>

<!-- Container for clock -->
<h1 id="clock"><time>Timer:00:00</time></h1>

<div class="difficulty">
<h2>You have 2 minutes</h2>
<h2>How many seconds:</h2>

<form>
<select id="options" title="values">
<!-- <option selected disabled>How many seconds</option> -->
<option value="3">3</option>
<option value="5">5</option>
<option value="8">8</option>
</select>
</form>

<!-- A Button that loads the js file -->
<button type="button" value="Submit" onclick="myclick()">
Submit
<div id="mylink"></div>
</button>
<script type="text/javascript">
</script>
</div>

<div id="cou"></div>
<div id="board"></div>






javascript html css






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 12 '18 at 17:08









Nik

1209




1209










asked Nov 12 '18 at 13:49









theMan23theMan23

12




12












  • you can access style attributes cardelement.style.visibility = "hidden"; or you could use jquery $("cardlement-selector").hide();

    – gp.
    Nov 12 '18 at 14:36











  • where could i put the .style.visiblity = "hidden" in the code?

    – theMan23
    Nov 12 '18 at 14:39











  • As you mentioned that after matching the cards you want to hide those cards, so simply put the above code where you check if the cards are matching.

    – Nik
    Nov 12 '18 at 14:54











  • document.getElementById("tile").style.visibility = "hidden"; I tried this after checking if they are === but no luck.

    – theMan23
    Nov 12 '18 at 15:00

















  • you can access style attributes cardelement.style.visibility = "hidden"; or you could use jquery $("cardlement-selector").hide();

    – gp.
    Nov 12 '18 at 14:36











  • where could i put the .style.visiblity = "hidden" in the code?

    – theMan23
    Nov 12 '18 at 14:39











  • As you mentioned that after matching the cards you want to hide those cards, so simply put the above code where you check if the cards are matching.

    – Nik
    Nov 12 '18 at 14:54











  • document.getElementById("tile").style.visibility = "hidden"; I tried this after checking if they are === but no luck.

    – theMan23
    Nov 12 '18 at 15:00
















you can access style attributes cardelement.style.visibility = "hidden"; or you could use jquery $("cardlement-selector").hide();

– gp.
Nov 12 '18 at 14:36





you can access style attributes cardelement.style.visibility = "hidden"; or you could use jquery $("cardlement-selector").hide();

– gp.
Nov 12 '18 at 14:36













where could i put the .style.visiblity = "hidden" in the code?

– theMan23
Nov 12 '18 at 14:39





where could i put the .style.visiblity = "hidden" in the code?

– theMan23
Nov 12 '18 at 14:39













As you mentioned that after matching the cards you want to hide those cards, so simply put the above code where you check if the cards are matching.

– Nik
Nov 12 '18 at 14:54





As you mentioned that after matching the cards you want to hide those cards, so simply put the above code where you check if the cards are matching.

– Nik
Nov 12 '18 at 14:54













document.getElementById("tile").style.visibility = "hidden"; I tried this after checking if they are === but no luck.

– theMan23
Nov 12 '18 at 15:00





document.getElementById("tile").style.visibility = "hidden"; I tried this after checking if they are === but no luck.

– theMan23
Nov 12 '18 at 15:00












1 Answer
1






active

oldest

votes


















0














You could do something like this:






function hideThatDiv() 
document.getElementById("hideThis").style.display = "none";

<div id="hideThis">I will be hidden</div>
<input type="button" onclick="hideThatDiv()" value="Click me to hide it">





Alternatively you could use jQuery:






function hideThatDiv() 
$('#hideThis').hide()

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="hideThis">I will be hidden</div>
<input type="button" onclick="hideThatDiv()" value="Click me to hide it">








share|improve this answer

























  • I get the idea but how can I add this into my code. That is what I am trying to do.

    – theMan23
    Nov 12 '18 at 14:54











  • @theMan23 What's the element you want to hide?

    – valbuxvb
    Nov 12 '18 at 14:55











  • document.getElementById("tile").style.visibility = "hidden"; I tried this after checking if they are === but no luck.

    – theMan23
    Nov 12 '18 at 14:58











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53263576%2fhidden-style-visiblity-on-card-flipping-game-javascript%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














You could do something like this:






function hideThatDiv() 
document.getElementById("hideThis").style.display = "none";

<div id="hideThis">I will be hidden</div>
<input type="button" onclick="hideThatDiv()" value="Click me to hide it">





Alternatively you could use jQuery:






function hideThatDiv() 
$('#hideThis').hide()

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="hideThis">I will be hidden</div>
<input type="button" onclick="hideThatDiv()" value="Click me to hide it">








share|improve this answer

























  • I get the idea but how can I add this into my code. That is what I am trying to do.

    – theMan23
    Nov 12 '18 at 14:54











  • @theMan23 What's the element you want to hide?

    – valbuxvb
    Nov 12 '18 at 14:55











  • document.getElementById("tile").style.visibility = "hidden"; I tried this after checking if they are === but no luck.

    – theMan23
    Nov 12 '18 at 14:58
















0














You could do something like this:






function hideThatDiv() 
document.getElementById("hideThis").style.display = "none";

<div id="hideThis">I will be hidden</div>
<input type="button" onclick="hideThatDiv()" value="Click me to hide it">





Alternatively you could use jQuery:






function hideThatDiv() 
$('#hideThis').hide()

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="hideThis">I will be hidden</div>
<input type="button" onclick="hideThatDiv()" value="Click me to hide it">








share|improve this answer

























  • I get the idea but how can I add this into my code. That is what I am trying to do.

    – theMan23
    Nov 12 '18 at 14:54











  • @theMan23 What's the element you want to hide?

    – valbuxvb
    Nov 12 '18 at 14:55











  • document.getElementById("tile").style.visibility = "hidden"; I tried this after checking if they are === but no luck.

    – theMan23
    Nov 12 '18 at 14:58














0












0








0







You could do something like this:






function hideThatDiv() 
document.getElementById("hideThis").style.display = "none";

<div id="hideThis">I will be hidden</div>
<input type="button" onclick="hideThatDiv()" value="Click me to hide it">





Alternatively you could use jQuery:






function hideThatDiv() 
$('#hideThis').hide()

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="hideThis">I will be hidden</div>
<input type="button" onclick="hideThatDiv()" value="Click me to hide it">








share|improve this answer















You could do something like this:






function hideThatDiv() 
document.getElementById("hideThis").style.display = "none";

<div id="hideThis">I will be hidden</div>
<input type="button" onclick="hideThatDiv()" value="Click me to hide it">





Alternatively you could use jQuery:






function hideThatDiv() 
$('#hideThis').hide()

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="hideThis">I will be hidden</div>
<input type="button" onclick="hideThatDiv()" value="Click me to hide it">








function hideThatDiv() 
document.getElementById("hideThis").style.display = "none";

<div id="hideThis">I will be hidden</div>
<input type="button" onclick="hideThatDiv()" value="Click me to hide it">





function hideThatDiv() 
document.getElementById("hideThis").style.display = "none";

<div id="hideThis">I will be hidden</div>
<input type="button" onclick="hideThatDiv()" value="Click me to hide it">





function hideThatDiv() 
$('#hideThis').hide()

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="hideThis">I will be hidden</div>
<input type="button" onclick="hideThatDiv()" value="Click me to hide it">





function hideThatDiv() 
$('#hideThis').hide()

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="hideThis">I will be hidden</div>
<input type="button" onclick="hideThatDiv()" value="Click me to hide it">






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 12 '18 at 15:00

























answered Nov 12 '18 at 14:46









valbuxvbvalbuxvb

6213




6213












  • I get the idea but how can I add this into my code. That is what I am trying to do.

    – theMan23
    Nov 12 '18 at 14:54











  • @theMan23 What's the element you want to hide?

    – valbuxvb
    Nov 12 '18 at 14:55











  • document.getElementById("tile").style.visibility = "hidden"; I tried this after checking if they are === but no luck.

    – theMan23
    Nov 12 '18 at 14:58


















  • I get the idea but how can I add this into my code. That is what I am trying to do.

    – theMan23
    Nov 12 '18 at 14:54











  • @theMan23 What's the element you want to hide?

    – valbuxvb
    Nov 12 '18 at 14:55











  • document.getElementById("tile").style.visibility = "hidden"; I tried this after checking if they are === but no luck.

    – theMan23
    Nov 12 '18 at 14:58

















I get the idea but how can I add this into my code. That is what I am trying to do.

– theMan23
Nov 12 '18 at 14:54





I get the idea but how can I add this into my code. That is what I am trying to do.

– theMan23
Nov 12 '18 at 14:54













@theMan23 What's the element you want to hide?

– valbuxvb
Nov 12 '18 at 14:55





@theMan23 What's the element you want to hide?

– valbuxvb
Nov 12 '18 at 14:55













document.getElementById("tile").style.visibility = "hidden"; I tried this after checking if they are === but no luck.

– theMan23
Nov 12 '18 at 14:58






document.getElementById("tile").style.visibility = "hidden"; I tried this after checking if they are === but no luck.

– theMan23
Nov 12 '18 at 14:58


















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53263576%2fhidden-style-visiblity-on-card-flipping-game-javascript%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Use pre created SQLite database for Android project in kotlin

Darth Vader #20

Ondo