Skip to content
This repository was archived by the owner on Oct 1, 2025. It is now read-only.

Commit a9153fc

Browse files
committed
feat: Coding Challenge 1 of DS and Modern Operators Done
1 parent a57e6b0 commit a9153fc

File tree

1 file changed

+106
-0
lines changed

1 file changed

+106
-0
lines changed
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/*
2+
We're building a football betting app (soccer for my American friends 😅)!;;
3+
Suppose we get data from a web service about a certain game('game' variable on
4+
next page).In this challenge we're gonna work with that data.
5+
Your tasks:
6+
1. Create one player array for each team(variables 'players1' and
7+
'players2')
8+
2. The first player in any player array is the goalkeeper and the others are field;
9+
players.For Bayern Munich(team 1) create one variable('gk') with the
10+
goalkeeper's name, and one array ('fieldPlayers') with all the remaining 10
11+
field players;
12+
3. Create an array 'allPlayers' containing all players of both teams(22
13+
players);
14+
4. During the game, Bayern Munich(team 1) used 3 substitute players.So create a;
15+
new array('players1Final') containing all the original team1 players plus;
16+
'Thiago', 'Coutinho' and 'Perisic';
17+
5. Based on the game.odds object, create one variable for each odd(called
18+
'team1', 'draw' and 'team2')
19+
6. Write a function ('printGoals') that receives an arbitrary number of player;
20+
names(not an array) and prints each of them to the console, along with the
21+
number of goals that were scored in total(number of player names passed in);
22+
7. The team with the lower odd is more likely to win.Print to the console which
23+
team is more likely to win, without using an if/else statement or the ternary
24+
operator.
25+
Test data for 6.: First, use players 'Davies', 'Muller', 'Lewandowski' and 'Kimmich'.
26+
Then, call the function again with players from game.scored
27+
GOOD LUCK 😀
28+
The Complete JavaScript Course 16;
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',
64+
'Hummels'],
65+
date: 'Nov 9th, 2037',
66+
odds: {
67+
team1: 1.33,
68+
x: 3.25,
69+
team2: 6.5,
70+
},
71+
};
72+
73+
const [players1, players2] = game.players;
74+
console.log(`Team 1 Players: ${ players1 }`);
75+
console.log(`Team 2 Players: ${ players2 }`);
76+
77+
const [gk, ...fieldPlayers] = [...players1];
78+
console.log(`Goalkeeper: ${ gk }`);
79+
console.log(`Field Players: ${ fieldPlayers }`);
80+
81+
const players = [...players1, ...players2];
82+
console.log(`All Players: ${ players }`);
83+
84+
const players1Final = [...players1, 'Thiago', 'Coutinho', 'Perisic'];
85+
console.log(`Team 1 Players Final: ${ players1Final }`);
86+
87+
const { team1, x: draw, team2 } = game.odds;
88+
console.log(`Odds\nTeam 1: ${ team1 }\nDraw: ${ draw }\nTeam 2: ${ team2 }`);
89+
90+
function printGoals (...players)
91+
{
92+
let goals = 'Goals';
93+
94+
for (let player of players) goals = goals.concat('\n', player);
95+
96+
console.log(`${ goals }\n\nTotal: ${ players.length }`);
97+
}
98+
99+
printGoals('Davies', 'Muller', 'Lewandowski', 'Kimmich');
100+
printGoals(...game.scored);
101+
102+
const drawLikely = (draw >= team1 && draw >= team2);
103+
104+
drawLikely && console.log('Draw is likely');
105+
(!drawLikely && team1 > team2) && console.log('Team 1 is likely to win');
106+
(!drawLikely && team2 > team1) && console.log('Team 2 is likely to win');

0 commit comments

Comments
 (0)