Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #40779
| Path | csiph.com!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
| Newsgroups | comp.lang.javascript |
| Subject | Re: How come I don't get a box when I add an eventlistener? |
| Date | Wed, 09 Feb 2022 21:53:33 +0000 |
| Organization | A noiseless patient Spider |
| Lines | 57 |
| Message-ID | <87y22jlnaa.fsf@bsb.me.uk> (permalink) |
| References | <24969684-2577-4eb1-b316-0b490769f615n@googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain |
| Injection-Info | reader02.eternal-september.org; posting-host="5ae0e0286c332dbca1a767f49131889a"; logging-data="9459"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+C6OwlWeVpaoFIsOEBpP3OXchO2jOFrQ4=" |
| Cancel-Lock | sha1:yx0ldhQeiLHeM9akitbDZPZwNBg= sha1:YyhsApZp01/aA6pUHRRlqvoGsCY= |
| X-BSB-Auth | 1.70a29e80a74a7cad7b68.20220209215333GMT.87y22jlnaa.fsf@bsb.me.uk |
| Xref | csiph.com comp.lang.javascript:40779 |
Show key headers only | View raw
chad altenburg <cdalten@gmail.com> writes:
> When I comment out the event listener code, I get a black
> box. However, when I don't, I don't get a black box. Why?
Because there is a syntax error. The code can't run if the interpreter
can't make sense of what you've written.
> <html>
> <canvas id = "canvas"></canvas>
> <script>
> var x = 20;
> var y = 20;
>
> var canvas = document.getElementById('canvas');
> var ctx = canvas.getContext('2d');
> var i =0;
>
> addEventListener();
Remove this as well. It will cause a run-time error.
> function drawSnake()
> {
> for (i = 0; i < 20; i++) {
> ctx.fillRect(x, y, 25, 25);
> }
> }
>
> drawSnake();
>
> function addListener() {
> document.addEventListener('keydown', function(e)) {
That second ) is in the wrong place.
> switch(e.keycode) {
> case 37: break; //left
> case 38: break; //up
> case 39: break; //right
> }
> }
It should be here (along with a semicolon)..
> }
>
>
>
> //ctx.fillRect(50, 100, 150, 150);
> // }
>
> </script>
> </html>
--
Ben.
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
How come I don't get a box when I add an eventlistener? chad altenburg <cdalten@gmail.com> - 2022-02-09 09:42 -0800
Re: How come I don't get a box when I add an eventlistener? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2022-02-09 21:53 +0000
Re: How come I don't get a box when I add an eventlistener? chad altenburg <cdalten@gmail.com> - 2022-02-10 10:18 -0800
Re: How come I don't get a box when I add an eventlistener? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2022-02-10 19:47 +0000
Re: How come I don't get a box when I add an eventlistener? chad altenburg <cdalten@gmail.com> - 2022-02-10 19:13 -0800
Re: How come I don't get a box when I add an eventlistener? The Natural Philosopher <tnp@invalid.invalid> - 2022-02-11 17:37 +0000
Re: How come I don't get a box when I add an eventlistener? Arno Welzel <usenet@arnowelzel.de> - 2022-02-12 18:05 +0100
Re: How come I don't get a box when I add an eventlistener? Arno Welzel <usenet@arnowelzel.de> - 2022-02-10 14:55 +0100
csiph-web