MCPcopy Create free account
hub / github.com/codemistic/Web-Development / keyCode

Function keyCode

Move the Ball/script.js:28–61  ·  view source on GitHub ↗
(keyPress)

Source from the content-addressed store, hash-verified

26
27// When using event.keyCode;
28function keyCode(keyPress) {
29
30 var top = parseInt(ball.style.top);
31 var left = parseInt(ball.style.left);
32
33 // W is pressed
34 if (keyPress === 119 || keyPress === 87) {
35 if (top > 5) {
36 ball.style.top = setValue(top - 5);
37 }
38 }
39
40 // A is pressed
41 else if (keyPress === 97 || keyPress === 65) {
42 if (left > 5) {
43 ball.style.left = setValue(left - 5);
44 }
45 }
46
47 // S is pressed
48 else if (keyPress === 115 || keyPress === 83) {
49 if (top < (window.innerHeight - ballHeight) - 5) {
50 ball.style.top = setValue(top + 5);
51 }
52 }
53
54 // D is pressed
55 else if (keyPress === 100 || keyPress === 68) {
56 if (left < (window.innerWidth - ballWidth) - 5) {
57 ball.style.left = setValue(left + 5);
58 }
59 }
60
61};
62
63
64

Callers 1

script.jsFile · 0.85

Calls 1

setValueFunction · 0.85

Tested by

no test coverage detected