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 need help with really simple Javascript

hahahanne

New Coder
Trying to complete a course in PHP, which involves Javascript. my code is 100% the same as my "Teachers" His code is working but mine isn´t... The course i am taking is 3 years old so i get no help from the instructor.. been stuck at this chapter for a week now and it´s driving me literally insane as i don´t understand JS at all...

Code:
<!DOCTYPE html>

<html>

<head>

    <title>Canvas</title>

    <style>

        #myCanvas{

            border:1px #000 solid;

            background:#f4f4f4;

        }



    </style>

</head>

<body>

     <canvas id="myCanvas" width="300" height="300"></canvas>

     <script>

         var c = document.getElementById('myCanvas')

         var ctx = c.getContext('2d');



         //Rectangle

         ctx.fillStyle='#34ebbd';

         ctx.fillRect(75,75 150, 150);







     </script>



</body>

</html>





everything is 100% same as the instructor at this stage his rectangle get filled in the middle by a red square, Where my JS won´t execute at all ? It makes no difference it´s just stuck with it´s #f4f4f4 background...
 
Last edited:
Hey @hahahanne! Welcome to the forum. I just spend a little while looking at your code, baffled as to why it wasn't working as well. And then I noticed a little something that fixed it!

Your code here is missing a comma (between the 75 and 150):

JavaScript:
ctx.fillRect(75,75 150, 150);
 
Hey @hahahanne! Welcome to the forum. I just spend a little while looking at your code, baffled as to why it wasn't working as well. And then I noticed a little something that fixed it!

Your code here is missing a comma (between the 75 and 150):

JavaScript:
ctx.fillRect(75,75 150, 150);
Thank you a thousand times! It worked like a charm i've spent so much time looking at the code so this little mistake just slipped right through.

Now i can finally continue with my course :) thanks again!
 

Buy us a coffee!

Back
Top Bottom