From f133ac51224625054564dc3d1aa7ab4bb3ae2404 Mon Sep 17 00:00:00 2001 From: Sparsh Pathak <54447950+spathak98@users.noreply.github.com> Date: Fri, 11 Mar 2022 20:56:04 +0530 Subject: [PATCH 1/3] Update app.js --- src/app.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/app.js b/src/app.js index cc43cc2..83f6e37 100644 --- a/src/app.js +++ b/src/app.js @@ -26,14 +26,28 @@ const initPlayers = (players) => { let detailedPlayers = []; // Create players using for loop // Type your code here + for(let index=0;index{ + let random=Math.round(Math.random()) + return random===0?"hero":"villain" +} // getting random strength const getRandomStrength = () => { // Return a random integer (0,100] // Note: You can use Math.random() and Math.ceil() + return Math.round(Math.random()*100)+1 } const buildPlayers = (players, type) => { @@ -42,6 +56,16 @@ const buildPlayers = (players, type) => { // Loop through players and accumulate HTML template // depending of type of player(hero|villain) // Type your code here + for(let index=0;index + +
${players[index].name}
+
${players[index].strength}
+ ` + fragment+=temp + } + } return fragment; } From 9c322d56e5999273bee7a1bd4b331890d3016e6b Mon Sep 17 00:00:00 2001 From: Sparsh Pathak <54447950+spathak98@users.noreply.github.com> Date: Mon, 21 Mar 2022 10:17:58 +0530 Subject: [PATCH 2/3] Update app.js --- src/app.js | 50 ++++++++++++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 22 deletions(-) diff --git a/src/app.js b/src/app.js index 83f6e37..1163f58 100644 --- a/src/app.js +++ b/src/app.js @@ -26,55 +26,61 @@ const initPlayers = (players) => { let detailedPlayers = []; // Create players using for loop // Type your code here - for(let index=0;index{ - let random=Math.round(Math.random()) - return random===0?"hero":"villain" + +function herovillian(n) { + if (n % 3 == 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() - return Math.round(Math.random()*100)+1 + var x = Math.ceil(Math.random() * 100); + return x; } const buildPlayers = (players, type) => { let fragment = ''; // Loop through players and accumulate HTML template + // depending of type of player(hero|villain) // Type your code here - for(let index=0;index - -
${players[index].name}
-
${players[index].strength}
- ` - fragment+=temp + + for (var i = 0; i < players.length; i++) { + player = `
+ +
${players[i].name}
+
${players[i].strength}
+
`; + if (players[i].type == type) { + fragment += player; } + // return fragment; } - return fragment; } + // Display players in HTML const viewPlayers = (players) => { document.getElementById('heroes').innerHTML = buildPlayers(players, 'hero'); document.getElementById('villains').innerHTML = buildPlayers(players, 'villain'); - } window.onload = () => { From da284cff6f7690ffa4a8c1291ff0002e1892c728 Mon Sep 17 00:00:00 2001 From: Sparsh Pathak <54447950+spathak98@users.noreply.github.com> Date: Mon, 21 Mar 2022 10:20:58 +0530 Subject: [PATCH 3/3] Update app.js --- src/app.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app.js b/src/app.js index 1163f58..75f15f6 100644 --- a/src/app.js +++ b/src/app.js @@ -39,7 +39,7 @@ const initPlayers = (players) => { } function herovillian(n) { - if (n % 3 == 0) { + if (n % 2 == 0) { return "hero"; } else { return "villain";