-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathlesson-11.html
More file actions
116 lines (99 loc) · 2.57 KB
/
lesson-11.html
File metadata and controls
116 lines (99 loc) · 2.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<html>
<head>
<link rel="stylesheet"
href="./style.css">
</link>
<style>
#bug {
position: absolute;
transition: linear 0.3s all;
transform-origin: 50% 50%;
font-size: 45px;
}
#web {
position: absolute;
font-size: 90px;
}
#flower {
font-size: 45px;
position: absolute;
}
.wrapper {
background-image: linear-gradient(0deg, #3b5236, #476839, #547f3c, #60963e);
position: relative;
width: 500px;
height: 500px;
overflow: hidden;
}
</style>
</head>
<body>
<a href="./index.html">Home</a>
<h1>Lesson 11 - Web Development</h1>
<div class="dotted-div">
<h2>Task 1: Lady Bug</h2>
<p>Can you recreate the functions from the last lesson, but this time, connect them to the up/down/left/right arrow
keys on your keyboard?</p>
<p>The "down" function has already been completed for you.</p>
<h3>Bonus Task: Add a "you win!" popup if the ladybug gets to the flower. Add a 'game over' popup if the ladybug
bumps into the web.</h3>
</div>
<div class="wrapper">
<div id="bug">🐞</div>
<div id="flower">🌸</div>
<div id="web">🕸</div>
</div>
<div class="key-takeaways">
<h2>Key Takeaways</h2>
<ul>
<li>
I can connect functions to keystrokes (e.g.: up, down, left, right).
</li>
<li>
I use JavaScript to manipulate HTML.
</li>
<li>
I can create more complicated if statements which depend on different variables.
</li>
</ul>
</div>
<a href="./lesson-10.html">Previous Lesson</a>
|
<a href="./whats-next.html">What's next?
</body>
<script>
let x = 0;
let y = 0;
let bug = document.querySelector("#bug");
function moveDown() {
y += 10;
bug.style.top = y;
bug.style.transform = "rotate(180deg)";
}
//TODO: Repeat these steps for the #up, #left and #right buttons
function keypress(e) {
if (e.code == "ArrowDown") {
moveDown();
} else if (e.code == "ArrowUp") {
//TODO
} else if (e.code == "ArrowLeft") {
//TODO
} else if (e.code == "ArrowRight") {
//TODO
}
}
document.onkeydown = keypress;
//TODO (Bonus): Can you add code to see if the ladybug has bumped into the flower or the web?
let flowerX = 150;
let flowerY = 150;
let score = 0;
let flower = document.querySelector("#flower");
flower.style.top = flowerY;
flower.style.left = flowerX;
let webX = 400;
let webY = 350;
let web = document.querySelector("#web");
web.style.top = webY;
web.style.left = webX;
</script>
</html>