-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunction-generator.html
76 lines (68 loc) · 2.08 KB
/
function-generator.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Function Generator</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
padding: 2rem;
}
p {
padding: .5rem 0;
}
div {
width: 100%;
height: 100vh;
background-color: rgb(0, 195, 255);
font-weight: 800;
font-size: 2rem;
font-family: sans-serif;
text-transform: uppercase;
display: flex;
justify-content: center;
align-items: center;
color: #0e0e0e;
}
</style>
</head>
<body>
<script>
/*
## Function Generator / Iterator
● Function generator adalah function yang digunakan untuk membuat data generator
● Generator adalah data yang bisa di interasi seperti Array
● Untuk membuat function generator, kita perlu menggunakan tanda * (bintang) setelah kata function
● Dan untuk mengembalikan data di tiap iterasi, kita bisa gunakan kata kunci yield diikuti datanya
*/
// =====Kode : Factorial Loop=====
document.writeln(`<p>=====Function Generator Sederhana=====</p>`);
function* createNames() {
yield "Fauzan";
yield "dopping";
yield "Tato";
}
for (const name of createNames()) {
document.writeln(`<p>${name}</p>`);
}
document.writeln(`<p>=====Function Generator Mulai Tidak Sederhana=====</p>`);
function createOddNumbers(num) {
for (let i = 1; i <= num; i++) {
if (i % 2 === 1) {
yield i;
}
}
}
let numbers = createOddNumbers(20);
for (const number of numbers) {
document.writeln(`<p>${number}</p>`);
}
</script>
</body>
</html>