Learn the fundamentals of pure javascript by building a memory card game. No frameworks or libraries, just vanilla JavaScript.
This video will cover how to:
‣ select elements in the DOM with querySelector
‣ iterate through lists with forEach
‣ add/remove an element class
‣ add/remove event listeners
‣ timeout
‣ html5: data-attribute
‣ css3: positioning, flexbox, perspective, backface-visibility, transitions
🔗Demo: https://marina-ferreira.github.io/memory-game/
💻Repo: https://github.com/code-sketch/memory-game/
💻Finished files: https://marina-ferreira.github.io/projects/js/memory-game/
⭐️ Course Contents ⭐️
⌨️ (00:00) Intro
⌨️ (00:47) Basic Structure / Create the Project
⌨️ (03:53) Board HTML
⌨️ (07:13) Board Styles
⌨️ (12:41) Flip Card
⌨️ (15:53) 3d Effect / CSS3 Perspective
⌨️ (18:25) Store Cards
⌨️ (22:37) Match Cards
⌨️ (25:12) Refactoring
⌨️ (27:27) Lock Board
⌨️ (28:53) Card Double Click
⌨️ (31:04) Shuffling
🎥Tutorial by Code Sketch. Check out the Code Sketch channel for more great tutorials: https://www.youtube.com/channel/UCHFmShpjG-8N52O0JD2ut3A/
—
Learn to code for free and get a developer job: https://www.freecodecamp.org
Read hundreds of articles on programming: https://medium.freecodecamp.org
And subscribe for new videos on technology every day: https://youtube.com/subscription_center?add_user=freecodecamp
Original source
37 responses to “Memory Card Game – JavaScript Tutorial”
Obrigado pelo tutorial
This is a great video. I've learnt that global variables are not good. What's the better way to put these variables in local?
“`
let flippedCard = false;
let lockBoard = false;
let firstCard, secondCard;
“`
the toggle doesnt work what i should do? 14:50
great video, very enjoyed the instructor. Just would like ask, how to set up the board for responsive design? I am bit lost with responsivity. Thank you
Brasil!!! 🇧🇷 😍
You have explained really very well but the problem is that it is not working on my web browser.
My bad !!!
all my cards are on top of each other?
Awesome tutorial!!! I learnt a lot from this – css positioning, dataset framework etc.
How can I get this to work in Internet explorer??
Hey there, first of all great tutorial!
Could you, please help me out adding an audio button that plays some instructions for example when clicked? Also how can be an audio added on each pair match and on each fail? And one final thing – how could you add a button that starts the game, before it's pressed the cards stay revealed to the player?
Thanks in advance.
1) Right click – Inspect Element? Game over. 2) Should be made pure dynamic, i.e. values dynamically added to cards, without hard-coded values. 3) Auto-reset after all matches or reset button present. 4) The firstCard shouldn't turn if you wait more than 1500 ms. etc.
Great tutorial! Please make a tutorial on how to make a chatbot with voice in JS ASAP! I really need it!
great tutorial. does anyone know how to add a counter feature and a message at the end when all tiles are flipped?
This code could have been simplified.
very good work. A lot a good stuff. Thank you very much for that.
I just want to say thank you so much for this tutorial
I am part of the Udacity Grow with Google Scholarship program and one of our projects is to build a memory game.
I had the hardest time grasping the JS part of it.
your tutorial helped so much and I passed my project with flying colors
Here is my version of your memory game
Enjoy
https://thenewmona.github.io/davidsmemorygame/
superv tutorial….. many many thanks
I've been putting off this same project off for about a year and this is awesome! Thanks for the very thorough explanation on all of the concepts.
ERROR in the code
firstly….this was a awesome tutorial by the instructor..thank you so much for that….
but there is error
i have tried the code by myself and giving the suggestion that there is a error….
in the double click logic
when we click the first time then "this"= the item we clicked and firstcard is not assigned …so returns..
but..when we click the second time we dont enter the if block again because hasflippedcard = true …so even when we double click on same cards the cards are matched….so adding ` if(this === firstcard){ return;} ` in the if block is wrong…. we should add it in the else block…that will work…
Try it… both the codes (said by the instructor and mine) and decide yourself.
What font-family type are you using in your vs code font, is it an plugin?
Great tutorial. Thanks!
I love this tutorial a lot. I feel like an idiot because I didn't knew half of what I saw here but I liked it a lot. I insta-subscribed to Code Sketch. Waiting for more videos!
Very good tutorial Marina ! Do you use a visual studio plugin to live reload ?
Fantastic tutor. Thanks!
Wish this was in Scrimba!
thanks heres my version: https://codepen.io/theweeknd/pen/gjKVVg i spent more work on it 😀
it's amazing, pretty work!!
Amazing, you are so cool and smart!!!!
holy crap that was the best position: absolute / relative explanation I've seen
Fantastic tutorial. It hit on so many different key skill sets to know.
In visual studio code you can get extensions like bioler html templates…. '" ! TAB" generates it instantly..
Kthxbye 🙃
Very clear and detail explanation. Awesome 👌
Congrats for this awesome tut'.
Thks i like it
Marina tu é Zika 🙂
Thanks for this great Tutorial.