-
Notifications
You must be signed in to change notification settings - Fork 17.5k
Expand file tree
/
Copy pathscript.js
More file actions
executable file
·223 lines (172 loc) · 4.58 KB
/
script.js
File metadata and controls
executable file
·223 lines (172 loc) · 4.58 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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
"use strict";
/*
function logger(myName) {
console.log(`My name is ${myName}`);
}
logger("Dan");
logger("Bob");
function fruitProcessor(apples, oranges) {
console.log(apples, oranges);
const juice = `Juice with ${apples} apples and ${oranges} oranges.`;
return juice;
}
console.log(fruitProcessor(5, 1));
const calcAge3 = (birthYear) => 2037 - birthYear;
console.log(calcAge3(1994));
const calcAverage = (scr1, scr2, scr3) => (scr1 + scr2 + scr3) / 3;
let scoreDolphins = calcAverage(44, 23, 71);
let scoreKoalas = calcAverage(65, 54, 49);
function checkWinner(avgDolphins, avgKoalas) {
if (avgKoalas > avgDolphins * 2) {
console.log(`Koalas win (${avgKoalas} vs. ${avgDolphins})`);
} else if (avgDolphins > avgKoalas * 2) {
console.log(`Koalas win (${avgDolphins} vs. ${avgKoalas})`);
} else {
console.log(`No team wins...`);
}
}
checkWinner(scoreDolphins, scoreKoalas);
*/
/*
const friends = ["Michael", "Steven", "Peter"];
console.log(friends);
console.log(friends[0]);
console.log(friends[2]);
console.log(friends.length);
console.log(friends[friends.length - 1]);
friends[2] = "Jay";
console.log(friends);
const dan = ["Dan", "Bekenstein", 2024 - 1994, "Product Manager", friends];
console.log(dan);
console.log(dan.length);
const calcAge = function (birthYear) {
return 2037 - birthYear;
};
const years = [1990, 1967, 2002, 2010, 2018];
const age1 = calcAge(years[0]);
const age2 = calcAge(years[1]);
const age3 = calcAge(years[years.length - 1]);
console.log(age1, age2, age3);
*/
/*
const friends = ["Michael", "Steven", "Peter"];
const newLength = friends.push("Jay");
console.log(friends);
console.log(newLength);
friends.unshift("John");
console.log(friends);
const popped = friends.pop();
console.log(friends);
console.log(popped);
friends.shift();
console.log(friends);
console.log(friends.indexOf("Steven"));
console.log(friends.includes("Peter"));
console.log(friends.includes("Dan"));
if (friends.includes("Steven")) {
console.log("You have a friend called Steven");
}
*/
/*
const dan = {
firstName: "Dan",
lastName: "Bekenstein",
age: 2024 - 1994,
job: "Product Manager",
friends: ["Tim", "Justin", "Greg"],
};
console.log(dan);
console.log(dan.lastName);
console.log(dan["lastName"]);
const nameKey = "Name";
console.log(dan["first" + nameKey]);
console.log(dan["last" + nameKey]);
// const interestedIn = prompt(
// "What do you want to know about Dan? Choose between firstName, lastName, age, job, and friends"
// );
// console.log(dan[interestedIn]);
dan.location = "US";
dan["city"] = "Boston";
console.log(dan);
console.log(
`${dan.firstName} has ${dan.friends.length} friends, and his best friend is called ${dan.friends[0]}`
);
const dan1 = {
firstName: "Dan",
lastName: "Bekenstein",
// age: 2024 - 1994,
job: "Product Manager",
friends: ["Tim", "Justin", "Greg"],
birthYear: 1994,
hasDriversLicense: true,
calcAge: function () {
this.age = 2024 - this.birthYear;
return this.age;
},
getSummary: function () {
return `${this.firstName} is a ${this.calcAge()}-year old ${
this.job
}, and he has ${this.hasDriversLicense ? "a" : "no"} driver's license.`;
},
};
console.log(dan1.calcAge());
console.log(dan1.age);
console.log(dan1.getSummary());
*/
// for (let rep = 1; rep <= 10; rep++) {
// console.log(`Lifting weights repetition ${rep}`);
// }
/*
const dan = [
"Dan",
"Bekenstein",
2024 - 1994,
"Product Manager",
["Tim", "Justin", "Greg"],
true,
];
const types = [];
for (let i = 0; i < dan.length; i++) {
console.log(dan[i], typeof dan[i]);
// types[i] = typeof dan[i];
types.push(typeof dan[i]);
}
console.log(types);
const years = [1991, 2007, 1969, 2020];
const ages = [];
for (let i = 0; i < years.length; i++) {
ages.push(2024 - years[i]);
}
console.log(years, ages);
const dan = [
"Dan",
"Bekenstein",
2024 - 1994,
"Product Manager",
["Tim", "Justin", "Greg"],
];
for (let i = dan.length - 1; i >= 0; i--) {
console.log(dan[i]);
}
for (let exercise = 1; exercise < 4; exercise++) {
console.log(`----Starting exercise---- ${exercise}`);
for (let rep = 1; rep < 6; rep++) {
console.log(`Lifting weight repetition ${rep}`);
}
}
*/
// for (let rep = 1; rep <= 10; rep++) {
// console.log(`Lifting weights repetition ${rep}`);
// }
// let rep = 1;
// while (rep <= 10) {
// console.log(`Lifting weights repetition ${rep}`);
// rep++;
// }
let dice = Math.trunc(Math.random() * 6) + 1;
// console.log(dice);
while (dice != 6) {
console.log(`You rolled a ${dice}`);
dice = Math.trunc(Math.random() * 6) + 1;
if (dice === 6) console.log("Loop is about to end...");
}