Skip to content

Commit eba5271

Browse files
committed
complete coding challenge
1 parent 82b2145 commit eba5271

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

Diff for: 09-Data-Structure-Modern-Operators-and-Strings/challenge.js

+46
Original file line numberDiff line numberDiff line change
@@ -219,3 +219,49 @@ console.log(scorers);
219219
// ----------------------------------------
220220
// Coding Challenge #3
221221
// ----------------------------------------
222+
223+
/*
224+
Let's continue with our football betting app! This time, we have a map with a log of the events that happened during the game, The values are the events themselves, and the keys are the minutes in which each event happened (a football game has 90 minutes plus some extra time).
225+
226+
1. Create an array 'events' of the different game events that happened (no duplicates).
227+
2. After the game has finished, it was found that the yellow card from minute 64 was unfair. So remove this event from the game events log.
228+
3. Print the following string to the console: "An event happened, on average every 9 minutes" (keep in mind that a game has 90 minutes).
229+
4. Loop over the events and log them to the console, marking wether it's in the first half or second half. (after 45min) of the game, like this: [FIRST HALF] 17: ⚽ GOAL
230+
*/
231+
232+
const gameEvents = new Map([
233+
[17, "⚽️ GOAL"],
234+
[36, "🔁 Substitution"],
235+
[47, "⚽️ GOAL"],
236+
[61, "🔁 Substitution"],
237+
[64, "🟨 Yellow card"],
238+
[69, "🟥 Red card"],
239+
[70, "🔁 Substitution"],
240+
[72, "🔁 Substitution"],
241+
[76, "⚽️ GOAL"],
242+
[80, "⚽️ GOAL"],
243+
[92, "🟨 Yellow card"],
244+
]);
245+
246+
// 1.
247+
const x = new Set(gameEvents.values());
248+
const events = [...x];
249+
console.log(events);
250+
251+
// 2.
252+
gameEvents.delete(64);
253+
console.log(gameEvents);
254+
255+
// 3.
256+
console.log(
257+
`An event happened, on average every ${90 / gameEvents.size} minutes`
258+
);
259+
260+
// 4.
261+
for (const [minutes, event] of gameEvents) {
262+
console.log(
263+
minutes <= 45
264+
? `[FIRST HALF] ${minutes}: ${event}`
265+
: `[SECOND HALF] ${minutes}: ${event}`
266+
);
267+
}

Diff for: index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010
</head>
1111
<body>
1212
<h1>Console.log</h1>
13-
<script src="09-Data-Structure-Modern-Operators-and-Strings/script.js"></script>
13+
<script src="09-Data-Structure-Modern-Operators-and-Strings/challenge.js"></script>
1414
</body>
1515
</html>

0 commit comments

Comments
 (0)