by Anonymous » 07 Apr 2025, 02:04
Code: Select all
*{
box-sizing: border-box;
}
.clear {
clear: both;
}
section {
border: 1px solid black;
height: 200px;
width: 50%;
float: left;
}< /code>
Card Game
Match-The-Cards
< /code>
< /div>
< /div>
< /p>
Ich schreibe einen Code, in dem die Elemente randomisiert und dann entfernt werden, sobald sie zweimal verwendet werden. Ich versuche, eine für
oder während Schleife zu schreiben, aber ich bekomme immer wieder unendliche Schleifen. Ich bin neu bei JS, also würde jede Unterstützung helfen.
Code: Select all
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)
}
}
[code]*{
box-sizing: border-box;
}
.clear {
clear: both;
}
section {
border: 1px solid black;
height: 200px;
width: 50%;
float: left;
}< /code>
Card Game
Match-The-Cards
< /code>
< /div>
< /div>
< /p>
Ich schreibe einen Code, in dem die Elemente randomisiert und dann entfernt werden, sobald sie zweimal verwendet werden. Ich versuche, eine für [/code] oder während Schleife zu schreiben, aber ich bekomme immer wieder unendliche Schleifen. Ich bin neu bei JS, also würde jede Unterstützung helfen.[code]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)
}
}[/code]