Skip to content

Commit dfc955d

Browse files
committed
feat: complete coding challenge 1
1 parent 1a19222 commit dfc955d

File tree

2 files changed

+107
-1
lines changed

2 files changed

+107
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/**
2+
Coding Challenge #1
3+
We're building a football betting app (soccer for my American friends 😅)!
4+
Suppose we get data from a web service about a certain game ('game' variable on
5+
next page). In this challenge we're gonna work with that data.
6+
Your tasks:
7+
1. Create one player array for each team (variables 'players1' and
8+
'players2')
9+
2. The first player in any player array is the goalkeeper and the others are field
10+
players. For Bayern Munich (team 1) create one variable ('gk') with the
11+
goalkeeper's name, and one array ('fieldPlayers') with all the remaining 10
12+
field players
13+
3. Create an array 'allPlayers' containing all players of both teams (22
14+
players)
15+
4. During the game, Bayern Munich (team 1) used 3 substitute players. So create a
16+
new array ('players1Final') containing all the original team1 players plus
17+
'Thiago', 'Coutinho' and 'Perisic'
18+
5. Based on the game.odds object, create one variable for each odd (called
19+
'team1', 'draw' and 'team2')
20+
6. Write a function ('printGoals') that receives an arbitrary number of player
21+
names (not an array) and prints each of them to the console, along with the
22+
number of goals that were scored in total (number of player names passed in)
23+
7. The team with the lower odd is more likely to win. Print to the console which
24+
team is more likely to win, without using an if/else statement or the ternary
25+
operator.
26+
Test data for 6.: First, use players 'Davies', 'Muller', 'Lewandowski' and 'Kimmich'.
27+
Then, call the function again with players from game.scored
28+
GOOD LUCK 😀
29+
**/
30+
31+
const game = {
32+
team1: "Bayern Munich",
33+
team2: "Borrussia Dortmund",
34+
players: [
35+
[
36+
"Neuer",
37+
"Pavard",
38+
"Martinez",
39+
"Alaba",
40+
"Davies",
41+
"Kimmich",
42+
"Goretzka",
43+
"Coman",
44+
"Muller",
45+
"Gnarby",
46+
"Lewandowski",
47+
],
48+
[
49+
"Burki",
50+
"Schulz",
51+
"Hummels",
52+
"Akanji",
53+
"Hakimi",
54+
"Weigl",
55+
"Witsel",
56+
"Hazard",
57+
"Brandt",
58+
"Sancho",
59+
"Gotze",
60+
],
61+
],
62+
score: "4:0",
63+
scored: ["Lewandowski", "Gnarby", "Lewandowski", "Hummels"],
64+
date: "Nov 9th, 2037",
65+
odds: {
66+
team1: 1.33,
67+
x: 3.25,
68+
team2: 6.5,
69+
},
70+
};
71+
72+
// 1.
73+
const [player1, player2] = game.players;
74+
console.log(player1, player2);
75+
76+
// 2.
77+
const [gk, ...fieldPlayers] = player1;
78+
console.log(gk, fieldPlayers);
79+
80+
// 3.
81+
const allPlayers = [...player1, ...player2];
82+
console.log(allPlayers);
83+
84+
// 4.
85+
const players1Final = [...player1, "Thiago", "Coutinho", "Perisic"];
86+
console.log(players1Final);
87+
88+
// 5.
89+
const {
90+
odds: { team1, x: draw, team2 },
91+
} = game;
92+
console.log(team1, draw, team2);
93+
94+
// 6.
95+
function printGoals(...players) {
96+
console.log(...players, `${players.length} goals scored ⚽`);
97+
}
98+
printGoals("Davies", "Muller", "Lewandowski", "Kimmich");
99+
printGoals(...game.scored);
100+
101+
// 7.
102+
console.log(
103+
game.odds.team1 < game.odds.team2 && "Team 1 is more likely to win",
104+
"\n",
105+
game.odds.team1 > game.odds.team2 && "Team 2 is more likely to win"
106+
);

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)