WIP
This commit is contained in:
parent
0168147c81
commit
c65a1e85b8
5 changed files with 20 additions and 101 deletions
|
@ -14,22 +14,28 @@ function makeArmy() {
|
|||
|
||||
let i = 0;
|
||||
while (i < 10) {
|
||||
let shooter = function() { // shooter function
|
||||
alert( i ); // should show its number
|
||||
let shooter = function() { // create a shooter function,
|
||||
alert( i ); // that should show its number
|
||||
};
|
||||
shooters.push(shooter);
|
||||
shooters.push(shooter); // and add it to the array
|
||||
i++;
|
||||
}
|
||||
|
||||
// ...and return the array of shooters
|
||||
return shooters;
|
||||
}
|
||||
|
||||
let army = makeArmy();
|
||||
|
||||
army[0](); // the shooter number 0 shows 10
|
||||
army[5](); // and number 5 also outputs 10...
|
||||
// ... all shooters show 10 instead of their 0, 1, 2, 3...
|
||||
*!*
|
||||
// all shooters show 10 instead of their numbers 0, 1, 2, 3...
|
||||
army[0](); // 10 from the shooter number 0
|
||||
army[1](); // 10 from the shooter number 1
|
||||
army[2](); // 10 ...and so on.
|
||||
*/!*
|
||||
```
|
||||
|
||||
Why do all of the shooters show the same value? Fix the code so that they work as intended.
|
||||
Why do all of the shooters show the same value?
|
||||
|
||||
Fix the code so that they work as intended.
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue