Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,30 @@ const initPlayers = (players) => {
let detailedPlayers = [];
// Create players using for loop
// Type your code here

for(var i=0;i<players.length;i++)
{
detailedPlayers[i]={
name:players[i],
strength:getRandomStrength(),
image:"images/super-"+(i+1)+".png"
};
if(i % 2 == 0)
{
detailedPlayers[i].type="hero";
}
else{
detailedPlayers[i].type="villain";
}
}
return detailedPlayers;
}

// getting random strength
const getRandomStrength = () => {
// Return a random integer (0,100]
// Note: You can use Math.random() and Math.ceil()
let s = Math.ceil(Math.random() * (100-1) + 1);
return s;
}

const buildPlayers = (players, type) => {
Expand All @@ -42,7 +58,13 @@ const buildPlayers = (players, type) => {
// Loop through players and accumulate HTML template
// depending of type of player(hero|villain)
// Type your code here

for(var i=0;i<players.length;i++)
{
if(players[i].type == type)
{
fragment+=`<div class="player"> <img src="${players[i].image}" alt=""> <div class="name">${players[i].name}</div> <div class="strength">${players[i].strength}</div> </div>`;
}
}
return fragment;
}
// Display players in HTML
Expand All @@ -55,4 +77,5 @@ const viewPlayers = (players) => {

window.onload = () => {
viewPlayers(initPlayers(PLAYERS));
}
}

3 changes: 2 additions & 1 deletion src/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
.player {
border-radius: 5px;
box-shadow: 0px 0px 2px 2px rgba(0, 0, 0, 0.2);
margin: 10px;
margin: 10px;
padding: 1rem;
text-align: center;
width: 100px;
Expand All @@ -42,3 +42,4 @@
margin-left: 80px;
font-size: 18px;
}