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 Please Help me make the computer game work correctly?


New Coder
Hi All,

Why won't this JavaScript code work? When I run it in Visual Studio the bird doesn't not move up and down
and there no game over box which restarts the came.

Please see in the link below at 8 hours and 52 minutes.
To view this content we will need your consent to set third party cookies.
For more detailed information, see our cookies page.

Best regards,


var hole = document.getElementById("hole");

var hole = document.getElementById("hole");
var game = document.getElementById("game");
var result = document.getElementById("result");
var text = document.getElementById("text");
var score = 0;
var jumping = 0;

function RanHole(){
var random =-((Math.random()*350)+150);
hole.style.top = random+"px";

var fall = setInterval(function(){
var birdTop = parseInt(window.getComputedSytle(bird).getPropertyValue("top"));
var blockLeft =parseInt(window.getComputedStyle(block).getPropertyValue("left"));
var holeTop = parseInt(window.getComputedSytle(hole).getPropertyValue("top"));
var hTop =(500+holeTop);
if((birdTop >450||((blockLeft<50)&&(blockLeft>-50)&&((birdTop<hTop)||(birdTop>hTop+100)))
text.innerText='Your final score is :${score}';
score = 0;


<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Flappy Bird</title>
<link rel="stylesheet" href="style.css">
<div id="game">
<div id="block"></div>
<div id="hole"></div>
<div id="bird"><img src="Bird1.png" alt="Bird"></div>
<div id="result">
<h1>Game Over</h1>
<p id="text"></p>
<button id="btn" onclick="location.reload()">Restart</button>
<script src="script.js"></script>

CSS Code


background-color: cadetblue;
background-image: -webkit-repeating-linear-gradient(rgb(175,75,75),rgb(31,31,31),rgb(59,153,148));
min-height: 800px;

height: 500px;
width: 400px;
border: 1px solid black;
background:url(bg2.jpg) ;
background-size: cover;
margin: 1rem auto;
overflow: hidden;

width: 50px;
height: 500px;
position: relative;
left: 400px;
animation: block 2s linear infinite;

@keyframes block{
left: 400px;
left: -50px;

height: 150px;
width: 50px;
background-color: yellow;
position: relative;
left: 400px;
animation: block 2s linear infinite;

position: fixed;
top: 100px;
height: 50px;
width: 50px

#bird img{
height: 50px;
width: 50px;

width: 500px;
background-color: brown;
margin: 5rem auto;
border: 2px solid white;
border-radius: 20px;
display: none;
text-align: center;

padding:0.5rem 1rem;
border: none;
border-radius: 11px;
background-color: green;
color: white;
font-size: 1.5rem;
margin-top: 1rem;
cursor: pointer;
margin-top: 1rem;
font-size: 2rem;
color: seashell;
Yanni, Please use the </> icon in the message toolbar above the text box to paste your code Makes things much easier to copy and paste for us.
If you had a good text editor, like VScode, you would have seen two errors in the JS.
if((birdTop >450||((blockLeft<50)&&(blockLeft>-50)&&((birdTop<hTop)||(birdTop>hTop+100)))
((blockLeft<50) Should only have a single parenthesis and the line is missing the closing parenthesis. Should Be:
if(birdTop >450||  ((blockLeft<50)&&(blockLeft>-50)&&((birdTop<hTop)||(birdTop>hTop+100)))){

And at the end you have

More to come
there no game over box
This is because
display: none;
The JS will reveal it here
    if(birdTop >450||  ((blockLeft<50) && (blockLeft>-50) && ((birdTop<hTop) || (birdTop>hTop+100)))){
        result.style.display="block";   // REVEALED HERE
        text.innerText='Your final score is :${score}';
        score = 0;

The bird should hop in the RanHole(){...} function - I think.

New Threads

Latest posts

Buy us a coffee!

Top Bottom