-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathExercise.html
More file actions
156 lines (112 loc) · 3.8 KB
/
Exercise.html
File metadata and controls
156 lines (112 loc) · 3.8 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
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<!-- in this lesson: -->
<!-- ------------------- -->
<!--
Lesson 8 : Objects
Exercise
-->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<!-- 🟩8j.~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<button onclick="playGame('heads')">Heads</button>
<button onclick="playGame('tails')">Tails</button>
<script>
//🟩8a.~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
const product = {
name: 'basketball',
price: 2095,
}
console.log(product);
//🟩8b.~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
product.price += 500;
console.log(product);
//🟩8c.~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
product[ 'delivery-time' ] = '3-days';
console.log(product)
//🟩8d.~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
let product1 = {
name: 'apple',
price: 100
}
let product2 = {
name: 'banana',
price: 50
}
function comparePrice (product1,product2)
{
if (product1.price > product2.price) {
return product2;
}
else {
return product1;
}
}
console.log(comparePrice(product1,product2))
//🟩8e.~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// console.log(product1 === product2);
function isSameProduct (product1,product2)
{
return (
product1.name = product2.name &&
product1.price === product2.price
)
}
console.log(isSameProduct(product1,product2))
//🟩8f.~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
let inputString = "JavaScript" // 🟨
const lowercaseString = inputString.toLowerCase();
console.log(lowercaseString);
// 🟦2nd Way
// lowercaseString = '';
// for (let i = 0; i < inputString.length; i++)
// {
// const char = inputString[ i ];
// lowercaseString += char.toLowerCase();
// }
// console.log('lowercaseString');
//🟩8g.~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// const repeatString = inputString.repeat(2);
// console.log(repeatString);
// 🟦2nd Way
const repeatCount = 2;
let repeatedString = '';
for (let i = 0; i < repeatCount; i++) {
repeatedString += inputString;
}
console.log(repeatedString);
// 🟦3rd Way
// const repeatCount = 2;
// let repeatedString = '';
// let i = 0;
// while (i < repeatString)
// {
// repeatedString += inputString;
// i++
// }
// console.log(repeatString);
//🟩8j.~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
let score = {
wins: 0,
losses: 0
}
function playGame (guess)
{
const randomNumber = Math.random();
const result = randomNumber < 0.5 ? 'heads' : 'tails'
console.log(guess === result ? 'You Win!' : 'You Lose!')
if (guess === result) {
score.wins++;
}
else {
score.losses++;
}
console.log(score);
}
</script>
</body>
</html>