*{
box-sizing: border-box;
}
.clear {
clear: both;
}
section {
border: 1px solid black;
height: 200px;
width: 50%;
float: left;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<!--<meta name="description" content="Your description goes here">
<meta name="keywords" content="one, two, three">-->
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Card Game</title>
<!-- external CSS link -->
<link rel="stylesheet" href="css/normalize.css">
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<h1>Match-The-Cards</h1>
<h2 id = "results"></h2>
<section id="one" class="one"></section>
<section id="two" class="one"></section>
<section id="three"class="one"></section>
<section id="four" class="one"></section>
<section id="five" class="one"></section>
<section id="six" class="one"></section>
<section id="seven"class="one"></section>
<section id="eight"class="one"></section>
<section id="nine" class="one"></section>
<section id="ten" class="one"></section>
<script type="text/javascript" src="js/main.js"></script>
</body>
</html>
I am writing a code where the items are randomized and then removed, once used twice. I am trying to write a for or while loop but keep getting infinite loops.
I did some research and it said to make an object of 0-4, then use object.key. I am new to JS, so any assistance would help.
const theFlipSide = {
cardOne: "🚕",
cardTwo: "🗽",
cardThree: "🌃",
cardFour: "🍕",
cardFive: "🍎"
}
console.log(theFlipSide);
const eachSection = Object.values(theFlipSide)
console.log(eachSection);
eachSectionReturn()
function eachSectionReturn() {
let items
let randomNumber = Math.floor(Math.random() * eachSection.length )
let theIndex = [0,1,2,3,4]
let randomEachSection = []
console.log(randomNumber, 'Random number');
console.log(theIndex, 'The index');
console.log(randomEachSection, 'random each section');
{
if (theIndex.find((e) => e == randomNumber) != undefined){
randomEachSection.push(eachSection[randomNumber] )
theIndex = theIndex.filter((e) => e != randomNumber)
console.log(theIndex,'filtered');
console.log(randomNumber, 'w/n if');
//return eachSection[Math.floor(Math.random() * eachSection.length)]
// allow that item to be outputted twice and then remove it from list
//_ => Math.random() - 0.5);
}
}
document.querySelectorAll('.one').forEach(section => section.addEventListener('click', theGame))
function theGame(e) {
let theSquares = eachSectionReturn()
e.target.innerText = (theSquares)
}
}