From 2bbaec116fd2450e479d5b79e9f0171cbbcac590 Mon Sep 17 00:00:00 2001 From: Sidharth PJ Date: Sat, 30 Apr 2022 20:47:32 +0530 Subject: [PATCH] VITFED47 --- src/app.js | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/app.js b/src/app.js index cc43cc2..f08d774 100644 --- a/src/app.js +++ b/src/app.js @@ -25,7 +25,14 @@ const PLAYERS = [ const initPlayers = (players) => { let detailedPlayers = []; // Create players using for loop - // Type your code here + players.forEach((player, i) => { + detailedPlayers.push({ + name: player, + image: "images/super-" + (i + 1) + ".png", + strength: getRandomStrength(), + type: i % 2 == 0 ? "hero" : "villain" + }); + }) return detailedPlayers; } @@ -34,14 +41,23 @@ const initPlayers = (players) => { const getRandomStrength = () => { // Return a random integer (0,100] // Note: You can use Math.random() and Math.ceil() -} + return Math.ceil(Math.random() * (100 - 1) + 1); +}; const buildPlayers = (players, type) => { let fragment = ''; // Loop through players and accumulate HTML template // depending of type of player(hero|villain) - // Type your code here + players.forEach((player) => { + fragment += ` +
+ +
${player.name}
+
${player.strength}
+
+ ` + }) return fragment; }