-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJS-test.js
More file actions
48 lines (43 loc) · 1.03 KB
/
JS-test.js
File metadata and controls
48 lines (43 loc) · 1.03 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
// 1 Programming Basics
let x
for (x = 10; x < 40; x++) {
if (x % 5 == 0 && x % 3 == 0) {
console.log(x + ' Jackpot!')
} else if (x % 3 == 0) {
console.log(x + ' This is divisible by 3')
} else if (x % 5 == 0) {
console.log(x + ' This is divisible by 5')
} else {
console.log(x)
}
}
// 2 DOM manipulation
let body = document.querySelector('body')
let button = document.createElement('button')
button.appendChild(document.createTextNode('Button'))
button.onclick = function () {
const h1 = createElement('h1')
h1.innerHTML = 'This is an h1 tag'
body.appendChild(h1)
}
// 3. Async API calls
async function test() {
const api = `https://catfact.ninja/fact`
const response = await fetch(api)
const data = await response.json()
for (let i = 0; i < 3; i++) {
console.log(data.answer)
}
}
test()
// 4.
class Product {
constructor(price, name) {
this.price = price
this.name = name
function logProduct() {
console.log(name + ' is ' + price + ' kr')
}
}
}
new Product('Hello', 500)