-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy path07 - Conditionals - Flows - Loops.html
89 lines (74 loc) · 2.25 KB
/
07 - Conditionals - Flows - Loops.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
77
78
79
80
81
82
83
84
85
86
87
88
89
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Getting Started with JavaScript</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/css/bootstrap.min.css">
<style>
body {
padding: 30px;
}
</style>
</head>
<body>
<div class="dogs-list"></div>
<!-- 🔥🔥🔥🔥 start javascript 🔥🔥🔥🔥 -->
<script>
/*
const name = prompt('What is your name?');
const username = 'chrisoncode';
*/
// if
// if (name == 'nick' || name == 'chris') {
// alert('Hello!');
// } else if (name == 'sam') {
// console.log('this is sam');
// } else {
// console.log('not nick');
// }
// for loop
const dogsList = document.querySelector('.dogs-list');
const dogs = [
{ name: 'bruce', type: 'chihuahua' },
{ name: 'chance', type: 'bernese' }
];
// for (let i = 0; i < dogs.length; i++) {
// // grab the dog
// const dog = dogs[i];
// const dogData = document.createElement('div');
// dogData.classList.add('jumbotron', 'text-center');
// dogData.innerText = `${dog.name} is a ${dog.type}`;
// dogsList.appendChild(dogData);
// }
// while loop
// let i = 0;
// while (i < dogs.length) {
// // grab the dog
// const dog = dogs[i];
// const dogData = document.createElement('div');
// dogData.classList.add('jumbotron', 'text-center');
// dogData.innerText = `${dog.name} is a ${dog.type}`;
// dogsList.appendChild(dogData);
// i++;
// }
// do while loop
// let i = 0;
// do {
// // grab the dog
// const dog = dogs[i];
// const dogData = document.createElement('div');
// dogData.classList.add('jumbotron', 'text-center');
// dogData.innerText = `${dog.name} is a ${dog.type}`;
// dogsList.appendChild(dogData);
// i++;
// } while (i < dogs.length);
// for...of iterator
for (let dog of dogs) {
const dogData = document.createElement('div');
dogData.classList.add('jumbotron', 'text-center');
dogData.innerText = `${dog.name} is a ${dog.type}`;
dogsList.appendChild(dogData);
}
</script>
</body>
</html>