Skip to content
Open
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
20 changes: 18 additions & 2 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,18 @@ const PLAYERS = [

// initialize players with image and strength
const initPlayers = (players) => {
let detailedPlayers = '';
let detailedPlayers = [];

// Instead of forloop use Map method
// Code here

players.map((player,i) => {
let char = {};
char.name=player;
char.strength=getRandomStrength();
char.image=`images/super-${i+1}.png`;
char.type = getRandomStrength() % 2 == 0 ? "hero" : "villain";
detailedPlayers.push(char);
})
return detailedPlayers;
}

Expand All @@ -43,6 +50,15 @@ const buildPlayers = (players, type) => {
// Instead of using for loop
// Use chaining of Array methods - filter, map and join
// Type your code here
fragment=players.filter((player) => player.type.toLowerCase() == type.toLowerCase())
.map((player, i) => {
return `<div class="player">
<img src="${player.image}" alt="">
<div class="name">${player.name}</div>
<div class="strength">${player.strength}</div>
</div>`;
})
.join("");

return fragment;
}
Expand Down