diff --git a/index.html b/index.html index 62790f2..2ef44b8 100644 --- a/index.html +++ b/index.html @@ -1,25 +1,22 @@ - - - - - + + + + Super Wars - - + + - +
-
-
-
-
-
-
+
+
+
- - - - - + + + + \ No newline at end of file diff --git a/src/app.js b/src/app.js index cc43cc2..0bc45c2 100644 --- a/src/app.js +++ b/src/app.js @@ -1,24 +1,4 @@ -const PLAYERS = [ - "Spiderman", - "Captain America", - "Wonderwoman", - "Popcorn", - "Gemwoman", - "Bolt", - "Antwoman", - "Mask", - "Tiger", - "Captain", - "Catwoman", - "Fish", - "Hulk", - "Ninja", - "Black Cat", - "Volverine", - "Thor", - "Slayer", - "Vader", - "Slingo" +const PLAYERS = ["Spiderman","Captain America", "Wonderwoman","Popcorn", "Gemwoman", "Bolt","Antwoman","Mask","Tiger", "Captain","Catwoman","Fish", "Hulk","Ninja","Black Cat","Volverine","Thor","Slayer","Vader", "Slingo" ]; // initialize players with image and strength @@ -26,15 +6,34 @@ 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; } - +function herovillian(n) { + if (n % 2 == 0) { + return "hero"; + } else { + return "villain"; + } +} // 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) => { let fragment = ''; @@ -42,9 +41,14 @@ 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 += `
${players[i].name}
${players[i].strength}
`; + } + } return fragment; -} +}; // Display players in HTML const viewPlayers = (players) => {