-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
52 lines (46 loc) · 1.36 KB
/
Copy pathscript.js
File metadata and controls
52 lines (46 loc) · 1.36 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
let count = 0;
/* 1st exercise:
Create a button with an onclick listener.
The onclick function should increase a count number, and console log it
*/
function clicked() {
console.log("i have been clicked");
//count = count + 1
// Shortened:
count = count + increaseAmount();
console.log(count);
const element = document.querySelector("h1");
//element.textContent = "New title";
// element.innerHTML = "New title";
// Solution 1
// element.textContent = "Your current count: " + count;
// Solution 2:
const span = document.querySelector("#count-amount");
span.textContent = count;
}
/* Solo Exercise
Add a "load" event listener to the window.
So you can greet your users welcome with an alert
*/
window.addEventListener("load", () => {
alert("Hello");
});
/* 2nd Exercise:
Create a h1 title with the text "Your current number".
add a double click listener programmatically to the h1.
So it resets the count.
*/
/* 3th Exercise:
Get the h1, and append the count
*/
/* 4th Exercise:
Create an input field type = number,
allow the user to control how much we increase pr. time
*/
function increaseAmount() {
const increment = document.querySelector("#increment-amount").value;
console.log(increment);
// Solution 1: return Number(increment)
// Solution 2
return +increment;
}