From 917bf795532c61c0a94453d106dacf5e967b6ae7 Mon Sep 17 00:00:00 2001 From: trishasinha22 Date: Sat, 2 Apr 2022 16:34:49 +0530 Subject: [PATCH] ProGrad ID: 8757 --- index.html | 4 ++-- src/app.js | 18 +++++++++++++++--- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/index.html b/index.html index 02aa4b4..9828030 100644 --- a/index.html +++ b/index.html @@ -6,7 +6,7 @@ Super Wars - + @@ -23,6 +23,6 @@ - + diff --git a/src/app.js b/src/app.js index 56cf472..6d3235e 100644 --- a/src/app.js +++ b/src/app.js @@ -23,13 +23,21 @@ 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((p,i) => { + let agent={}; + agent.name=p; + agent.strength = getRandomStrength(); + agent.image = `images/super-${i + 1}.png`; + agent.type = i % 2 == 0 ? "hero" : "villain"; + detailedPlayers.push(agent); + }); return detailedPlayers; -} +}; // getting random strength const getRandomStrength = () => { @@ -43,7 +51,11 @@ 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((p) => p.type == type).map((p,i) => {return `
+ +
${players[i].name}
+
${players[i].strength}
+
`}).join(""); return fragment; }