forked from tb-harris/manipualting-dom-project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
51 lines (42 loc) · 1.6 KB
/
script.js
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
// Get elements
paragraphDiv = document.getElementById("p-div");
imageDiv = document.getElementById("img-div");
let P_button = document.getElementById("p-button");
let Img_button = document.getElementById("img-button");
let Nothing_button = document.getElementById("nothing-button");
let pCount = 0;
function paragraph() {
// Hide image div and show paragraph div
imageDiv.style.display = "none";
paragraphDiv.style.display = "block";
// Create new paragraph element and add it to div
let newParagraph = document.createElement("p");
newParagraph.innerHTML = "Hot Chocolate is bad today";
paragraphDiv.appendChild(newParagraph);
// Increment pCount and update counter
pCount++;
document.getElementById("p-count").innerText = `pCount: ${pCount}`
}
let imgCount = 0;
function image() {
// Hide paragraph div and show image div
paragraphDiv.style.display = "none";
imageDiv.style.display = "block";
// Create new image and add it to div
let newImage = document.createElement("img");
newImage.src = "Pidgeotto.png";
imageDiv.appendChild(newImage);
// Increment imgCount and update counter
imgCount++;
document.getElementById("img-count").innerText = `imgCount: ${imgCount}`;
}
let nothingCount = 0;
function nothing(){
// Increment counter and update nothing counter
nothingCount++;
document.getElementById("nothing-count").innerHTML = `nothingCount: ${nothingCount}`;
}
// Event listeners
P_button.addEventListener("click", paragraph);
Img_button.addEventListener("click", image);
Nothing_button.addEventListener("click", nothing);