Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

JavaScript Memory games doesn't show

hello,
I'm trying to make the memory game from the youtube video
To view this content we will need your consent to set third party cookies.
For more detailed information, see our cookies page.
I did everything she did, check my code on a codechecker, double check my picture path but it still doesn't work

here's the html file

[CODE lang="html" title="memory.html"]<!DOCTYPE html>

<html lang="en" dir="ltr">

<head>

<meta charset="UTF-8">

<title>Memory game</title>

<link rel="stylesheet" href="style.css"></link>

<script src="app.js" charset="utf-8"></script>

</head>

<body>

<h3>Score:<span id="result"></span><h3>

<div class="grid">
</div>

</body>

</html>[/CODE]


here's the js file

[CODE lang="javascript" title="app.js"]document.addEventListener('DOMContentLoaded', ()=>{

const cardArray= [
{
name:'rooster',
img:'pictures/rooster.jpg.'
},
{
name:'monkey',
img:'monkey.jpg'
},
{
name:'robot',
img:'pictures/robot.jpg'
},
{
name:'mazinger',
img:'pictures/mazinger.jpg'
},
{
name:'book',
img:'pictures/book.jpg'
},
{
name:'megaman',
img:'pictures/megaman.jpg'
},
{
name:'rooster',
img:'pictures/rooster.jpg'
},
{
name:'monkey',
img:'monkey.jpg'
},
{
name:'robot',
img:'pictures/robot.jpg'
},
{
name:'mazinger',
img:'pictures/mazinger.jpg'
},
{
name:'book',
img:'pictures/book.jpg'
},
{
name:'megaman',
img:'pictures/megaman.jpg'
}
]

const grid = document.querySelector('.grid');

function createBoard(){
for (let i=0; i< cardArray.lenght; i++){
var card = document.createElement('img');
card.setAttribute('src', 'monkey.jpg');
card.setAttribute('data-id', i);
//card.addEventListener('click', flipcard);
grid.appendChild(card);
}
}

createBoard();

});
[/CODE]

and the css file
[CODE lang="css" title="style.css"].grid{
display:flex;
flex-wrap: wrap;
height:300px;
width: 400px;
}[/CODE]

Sorry for putting everything, but there's not much and I tought it would be easier.
The girl in the video executed that and she had the monkey picture repeated 12 times in a square.
Me i only have "score" show up.

thank you for your help
 
No, it's in a folder called pictures in the same folder as the html document.

memory [folder]
|
----memory.html
|
----app.js
|
---style.css
|
---pictures[folder]
|
----- monkey.jpg
|
----- rooster.jpg
|
etc...
 
it doesn't work : (

[CODE title="correction"]function createBoard(){
for (let i=0; i< cardArray.lenght; i++){
var card = document.createElement('img');
card.setAttribute('src', 'pictures/monkey.jpg');
card.setAttribute('data-id', i);
//card.addEventListener('click', flipcard);
grid.appendChild(card);
}
}[/CODE]
 
yes it does

[CODE title="picture in html"]<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="UTF-8">
<title>Memory game</title>
<link rel="stylesheet" href="style.css"></link>
<script src="app.js" charset="utf-8"></script>
</head>
<body>
<h3>Score:<span id="result"></span><h3>
<img src="pictures/monkey.jpg">
<div class="grid">

</div>
</body>
</html>[/CODE]
 
I think , in the JS file, it is
JavaScript:
for (let i=0; i< cardArray.length; i++){
rather than
JavaScript:
for (let i=0; i< cardArray.lenght; i++){
 

New Threads

Buy us a coffee!

Back
Top Bottom