Skip to content

Commit 1f145e5

Browse files
committed
conditions
1 parent 1576271 commit 1f145e5

File tree

3 files changed

+301
-0
lines changed

3 files changed

+301
-0
lines changed

playground/bedmas.html

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<meta name="viewport" content="width=device-width,initial-scale=1.0">
7+
<title>BEDMAS</title>
8+
<link rel="stylesheet" href="../base.css">
9+
</head>
10+
11+
<body>
12+
<p><abbr>B</abbr>rackets</p>
13+
<p><abbr>E</abbr>xponents</p>
14+
<p><abbr>D</abbr>ivision</p>
15+
<p><abbr>M</abbr>ultiplication</p>
16+
<p><abbr>A</abbr>ddition</p>
17+
<p><abbr>S</abbr>ubtraction</p>
18+
19+
<style>
20+
p {
21+
margin: 0;
22+
}
23+
24+
abbr {
25+
font-size: 50px;
26+
}
27+
</style>
28+
29+
<script>
30+
const age = 10 * 5 - 2; // 48
31+
const age2 = 10 * (5 - 2); // 30
32+
33+
function calculateBill(billAmount, taxRate = 0.13, tipRate = 0.15) {
34+
// this is the function body
35+
console.log('Running Calculate Bill!!');
36+
const total = billAmount + billAmount * taxRate + billAmount * tipRate;
37+
return total;
38+
}
39+
40+
const total = 128 + (25.6 - 19.2);
41+
42+
</script>
43+
44+
</body>
45+
46+
</html>
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<meta name="viewport" content="width=device-width,initial-scale=1.0">
7+
<title>If Statements</title>
8+
<link rel="stylesheet" href="../base.css">
9+
</head>
10+
11+
<body>
12+
* empty array
13+
* empty object
14+
15+
<h2>Truthy Values</h2>
16+
* 1
17+
* -10
18+
* full string
19+
* a string of "0"
20+
21+
<h2>Falsy Values</h2>
22+
* 0
23+
* undefined variable
24+
* Variable set to null
25+
* a variable set to `"hello" - 10` NaN
26+
* empty string
27+
28+
<script>
29+
const age = 100;
30+
if (age > 70) {
31+
console.log('In your seventies');
32+
} else if (age > 60) {
33+
console.log('In your sixties');
34+
} else if (age > 50) {
35+
console.log('In your 50s');
36+
} else {
37+
console.log('Nothing was true');
38+
}
39+
40+
function slugify(sentence, lowercase) {
41+
let slug = sentence.replace(/\s/g, '-');
42+
if (lowercase) {
43+
return slug.toLowerCase();
44+
}
45+
return slug;
46+
}
47+
48+
const name = 'wes';
49+
const last = 'bos';
50+
51+
if (name === 'scott' || (name === 'wes' && last == 'bos')) {
52+
console.log('Coool Name!');
53+
}
54+
55+
const isAwesomeName = 'awesome'.includes(name);
56+
if (isAwesomeName) {
57+
console.log('SUPER COOL AWESOME NAME');
58+
}
59+
60+
function nameIsAwesome(name) {
61+
return 'awesome'.includes(name);
62+
}
63+
64+
if (nameIsAwesome('wes')) {
65+
console.log('COOL NAME WES');
66+
}
67+
68+
const dog = '';
69+
70+
if (dog) {
71+
console.log('you have a dog');
72+
} else {
73+
console.log('you dont have a dog');
74+
}
75+
76+
let score = {};
77+
78+
if (score) {
79+
console.log('There is a score already');
80+
} else {
81+
console.log('No score yet');
82+
}
83+
84+
85+
const values = [[], {}, -10, 1, 0, '', 'full string', ' ', undefined, NaN, null, '0️⃣', '💩'];
86+
87+
console.group('truthy or falsy values');
88+
values.forEach(value => {
89+
if (value) {
90+
console.log(value, 'is truthy');
91+
} else {
92+
console.log(value, 'is falsy');
93+
}
94+
});
95+
console.groupEnd();
96+
97+
98+
</script>
99+
</body>
100+
101+
</html>

playground/if-statements.html

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<meta name="viewport" content="width=device-width,initial-scale=1.0">
7+
<title>If Statements</title>
8+
<link rel="stylesheet" href="../base.css">
9+
</head>
10+
11+
<body>
12+
* empty array
13+
* empty object
14+
15+
<h2>Truthy Values</h2>
16+
* 1
17+
* -10
18+
* full string
19+
* a string of "0"
20+
21+
<h2>Falsy Values</h2>
22+
* 0
23+
* undefined variable
24+
* Variable set to null
25+
* a variable set to `"hello" - 10` NaN
26+
* empty string
27+
28+
<script>
29+
const age = 100;
30+
if (age > 70) {
31+
console.log('In your seventies');
32+
} else if (age > 60) {
33+
console.log('In your sixties');
34+
} else if (age > 50) {
35+
console.log('In your 50s');
36+
} else {
37+
console.log('Nothing was true');
38+
}
39+
40+
function slugify(sentence, lowercase) {
41+
let slug = sentence.replace(/\s/g, '-');
42+
if (lowercase) {
43+
return slug.toLowerCase();
44+
}
45+
return slug;
46+
}
47+
48+
const name = 'wes';
49+
const last = 'bos';
50+
51+
if (name === 'scott' || (name === 'wes' && last == 'bos')) {
52+
console.log('Coool Name!');
53+
}
54+
55+
const isAwesomeName = 'awesome'.includes(name);
56+
if (isAwesomeName) {
57+
console.log('SUPER COOL AWESOME NAME');
58+
}
59+
60+
function nameIsAwesome(name) {
61+
return 'awesome'.includes(name);
62+
}
63+
64+
if (nameIsAwesome('wes')) {
65+
console.log('COOL NAME WES');
66+
}
67+
68+
const dog = '';
69+
70+
if (dog) {
71+
console.log('you have a dog');
72+
} else {
73+
console.log('you dont have a dog');
74+
}
75+
76+
let score = {};
77+
78+
if (score) {
79+
console.log('There is a score already');
80+
} else {
81+
console.log('No score yet');
82+
}
83+
84+
85+
const values = [[], {}, -10, 1, 0, '', 'full string', ' ', undefined, NaN, null, '0️⃣', '💩'];
86+
87+
console.group('truthy or falsy values');
88+
values.forEach(value => {
89+
if (value) {
90+
console.log(value, 'is truthy');
91+
} else {
92+
console.log(value, 'is falsy');
93+
}
94+
});
95+
console.groupEnd();
96+
97+
console.clear();
98+
99+
const isCool = true;
100+
101+
if (!isCool) {
102+
console.log('You are not cool');
103+
}
104+
105+
// ternary
106+
const count = 5234234;
107+
// let word;
108+
// if (count === 1) {
109+
// word = 'item';
110+
// } else {
111+
// word = 'items';
112+
// }
113+
114+
// 1. Condition
115+
// 2. what to do if true
116+
// 3. what to do if false
117+
const word = count === 1 ? 'item' : 'items';
118+
const sentence = `You have ${count} item${count === 1 ? '' : 's'} in your cart`;
119+
console.log(sentence);
120+
121+
function showAdminBar() {
122+
console.log('Showing admin bar');
123+
}
124+
const isAdmin = false;
125+
// isAdmin ? showAdminBar() : null;
126+
127+
// AND AND TRICK!
128+
function check1() {
129+
console.log('Running check 1');
130+
return true;
131+
}
132+
function check2() {
133+
console.log('Running check 2');
134+
return false;
135+
}
136+
function check3() {
137+
console.log('Running check 3');
138+
return true;
139+
}
140+
141+
if (check1() && check2() && check3()) {
142+
console.log('all checks passed');
143+
} else {
144+
console.log('Some checks failed');
145+
}
146+
// isAdmin ? showAdminBar() : null;
147+
isAdmin && showAdminBar();
148+
149+
if (isAdmin) { showAdminBar(); }
150+
151+
</script>
152+
</body>
153+
154+
</html>

0 commit comments

Comments
 (0)