forked from JTaylor-Code/html-js-drills
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathscript.js
More file actions
201 lines (164 loc) · 6.21 KB
/
script.js
File metadata and controls
201 lines (164 loc) · 6.21 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
// Helpful Resources:
// https://www.w3schools.com/js/js_htmldom.asp
// https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector
/*****************************
* Section 1 - Personal Info *
*****************************
*
* Description:
* Change the code below to display some (static) information
* when a user clicks the "Show Info" button.
*
* Resources:
* (See below for drill-specific resources)
*/
function addName() {
console.log("addName() ran");
// See:
// - https://www.digitalocean.com/community/tutorials/js-innertext-and-innerhtml
// - https://www.w3schools.com/jsref/prop_node_innertext.asp
let nameElement = document.querySelector("#name");
}
function addFavoriteThings() {
console.log("Called addFavoriteThings()");
let favoriteThings = document.querySelector("#favthings");
console.log(favoriteThings);
// 1. Get a reference to <ul id="favthings">
// 2. Create a few list items representing your favorite things
// 3. Add them to append them to favthings
// See:
// - https://htmldog.com/guides/javascript/advanced/creatingelements/
// - https://www.javascripttutorial.net/javascript-dom/javascript-createelement/
// - https://developer.mozilla.org/en-US/docs/Web/API/Document/createElement
}
function replaceImage() {
console.log("Called replaceImage()");
let image = document.querySelector("#picture");
console.log(image);
image.setAttribute("src", "pic.jpg");
// Change the puppy picture to a picture of your choosing
// See:
// - https://www.tutorialrepublic.com/javascript-tutorial/javascript-dom-get-set-attributes.php
// - https://www.w3schools.com/jsref/met_element_setattribute.asp
}
function changeCodeStatus() {
console.log("Called changeCodeStatus()");
// codeStatus.innerHTML=`<img src="doge.gif" alt="My Doge">`;
// 1. Get a reference to <div id="codestatus">
// 2. Create image element containing a sweet ol' meme
// 3. Replace text in codestatus w/ image
}
// Get a reference to the button w/ id="show-info-button"
let showInfoButton = document.querySelector("#show-info-button");
// Do something when showInfoButton is clicke
showInfoButton.addEventListener("click", function () {
console.log('Clicked "Show Info" button');
// Implement addName, addFavoriteThings, replaceImage, changeCodeStatus above
addName();
addFavoriteThings();
replaceImage();
changeCodeStatus();
});
/**********************************
* Section 2 - Reading From Forms *
**********************************
*
* Description:
* Change the code below to populate the section on the right-hand
* side of the page with the data entered into the form.
*
*/
// Get a reference to form w/ id="information-form"
let informationForm = document.querySelector("#information-form");
// Do something when form is submitted
informationForm.addEventListener("submit", function (event) {
event.preventDefault(); // You will want this here. Remove it and see what changes.
//var nameValue = document.getElementById("fname").value;
// Your job:
// 1. Get information typed into the form
// 2. Display that info in "Display that info here" section
// Google things like:
// javascript form element get values
});
/*************************************
* Section 3 - Clicks and Keypresses *
*************************************
*
* Description:
* Make the buttons in section 3 of index.html behave as described below.
*
*/
// When a user clicks "Click me to log something to the console"
// then log something to the console
// Fill in ________ to get a reference to the correct button on the page
let consoleLogButton = document.querySelector("#console-log-button");
// Log something when that button is clicked
consoleLogButton.addEventListener("click", function () {
console.log("Change this text if you want!");
});
let makeBlueButton = document.querySelector("#make-blue-button");
makeBlueButton.addEventListener("click", function () {
// Your job:
// 1. When a user clicks "Change the text to the right blue"
// 2. Change the text in <div id="colorText">...</div> to blue
});
// Adding an event listener to document means the "keydown" event
// can happen anywhere on the page and we'll respond.
document.addEventListener("keydown", function (event) {
// This is called whenever a user pressed any key.
// Your job:
// 1. Turn colorText red whenever a user presses the 'r' key
// 2. Add your own keybind somewhere
// See:
// - https://developer.mozilla.org/en-US/docs/Web/API/Document/keydown_event
// - https://javascript.info/keyboard-events
});
/*************************************
* Section 4 - TODO List *
*************************************
*
* Description:
* Build a simple TODO list.
*
* For this you will need to have a listener on the submit form and add
* anything entered into the text box to the to do list on the right side.
*
* Bonus:
* Add a delete button next to each item and allow it to delete the item
* it is next to.
*/
let toDoListForm = document.querySelector(".form");
console.log('todolistform',toDoListForm);
// Do something when form is submitted
toDoListForm.addEventListener("submit", function (event) {
});
// Your code goes here
/****************************************
* Section 5 - setInterval + setTimeout *
****************************************
*
* Description:
* Use the setInterval function to create a counter that counts every
* second on the page (Should look kind of like a stopwatch counting up).
* Display this in the span with the id of 'seconds'.
*
* Then use the SetTimeout function to display something (your choice) to the
* div with the id 'delayedDisplay' after 5 seconds have passed.
*
* Resources:
* - https://javascript.info/settimeout-setinterval
*
*/
// Your code goes here
/****************************************
* Section 6 - Your own section! *
****************************************
*
* Description:
* Add your own section to this page with its own event listeners.
* Use a JavaScript event listener that is new to you.
* Here is a handy list: https://developer.mozilla.org/en-US/docs/Web/Events
* Click on each event listener to see an example of how it is used
*
*/
// Your code goes here