In this programming tutorial, we’ll create a basic two player connect four game using Javascript, jQuery, CSS, and HTML. This tutorial is geared towards people who understand the basics of web technologies, but maybe want to watch how another developer builds a connect four application.
💻Code: https://github.com/codyseibert/js-connect-four
Check out Cody Seibert’s main channel: https://www.youtube.com/channel/UCsrVDPJBYeXItETFHG0qzyw
—
Learn to code for free and get a developer job: https://www.freecodecamp.com
Read hundreds of articles on programming: https://medium.freecodecamp.com
And subscribe for new videos on technology every day: https://youtube.com/subscription_center?add_user=freecodecamp
Original source
6 responses to “Connect Four with Javascript & jQuery – Tutorial”
Help!! I cant get the background color to show up:
body {
text-align: center;
}
connect4 {
background-color: yellow;
display: inline-block;
}
.col {
width: 70px;
height:70px;
display: inline-block;
background-color:rgb(255, 255, 255);
border-radius: 50%;
margin: 5px;
}
Great tutorial. The checking of the winner was a little bit to fast for me. But I think after watching this part some times I will get this, too.
I tried to replicate this project for learning purposes in vanilla js. But I have a problem rewriting the line 79:
$(this).trigger('mouseenter');
First I think I have to listen at the board on the mouseover event instead to test, what child element I hovered over (at line 47):
board.addEvenetListener('mouseover', function(e) {
if(e.target.classList.contains('empty) {
// find lastEmptyCell etc.
}
});
Then I think I have to trigger the mouseover event from the child element and let it bubble up to the board (line 79):
e.target.dispatchEvent(new Event('mouseover', { bubble: true });
But the event listener above does not catch this event. It is only called if i dispatch the event from the board (board.dispatchEvent(new Event('mouseover'))). But then I cannot access the actual cell, that was hovered in the event listener.
Has anyone an idea what I am making wrong?
EDIT:
I made a quick demo: https://codepen.io/anon/pen/pKMzYW?editors=1111
If I click on a child, I would expect, that the mouseover event listener gets triggered and logs the child id.
thank you for teaching this practical example … I successfully duplicated it and I have learned so much … again, jQuery is the saver …
Wow that hour flew by this had some great info in it
Thank u for this awesome video
Thanks for these great small projects videos.