Skip to content

Commit cbeea60

Browse files
committed
Updated start lesson 7
1 parent 150fd37 commit cbeea60

File tree

1 file changed

+10
-28
lines changed

1 file changed

+10
-28
lines changed

start/lesson7/index.html

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -20,39 +20,21 @@
2020
<body>
2121
<script>
2222
const npcs = [];
23-
const useWhile = true;
24-
25-
if (useWhile){
26-
for(let i=0; i<10; i++){
27-
npcs.push(createNPC());
28-
}
29-
}else{
30-
let i = 0;
31-
32-
while(i<10){
33-
npcs.push(createNPC());
34-
i++;
35-
}
36-
}
37-
38-
const npc = npcs[0];
39-
console.log("npcs[0] has the following properties... ");
40-
for(let prop in npc){
41-
console.log(prop + ":" + npc[prop]);
42-
}
43-
44-
let i=0;
45-
npcs.forEach( npc =>{
46-
console.log('NPC no.'+i+' uses a '+npc.weapon+' as its chosen weapon.');
47-
i++;
48-
})
4923

24+
npcs.push(createNPC());
25+
npcs.push(createNPC());
26+
npcs.push(createNPC());
27+
5028
function createNPC(){
29+
const power = Math.random() * 0.5 + 0.5;
30+
5131
const weapons = ["sword", "pistol", "axe", "spear"];
5232
const weapon = weapons[Math.floor(Math.random() * weapons.length)];
53-
const power = Math.random() * 0.5 + 0.5;
54-
const strength = Math.random() + 1.0;
33+
34+
const strength = Math.random()*2 + 1.0;
35+
5536
const damage = 0;
37+
5638
return { power, weapon, strength, damage };
5739
}
5840
</script>

0 commit comments

Comments
 (0)