Skip to content

Commit 66d9441

Browse files
Added first two bugus
1 parent da2b6d4 commit 66d9441

1 file changed

Lines changed: 101 additions & 0 deletions

File tree

fundamentals/bugChallenge.md

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
For each of the snippets below, explain the bugs in your own words.
2+
3+
# Bug 1
4+
5+
### code
6+
```
7+
for(var i = 0; i < 5; i++){
8+
setTimeout(function(){
9+
console.log(i+1);
10+
}, 100*i);
11+
}
12+
```
13+
14+
### actual output:
15+
```
16+
6
17+
6
18+
6
19+
6
20+
6
21+
```
22+
### expected output:
23+
```
24+
1
25+
2
26+
3
27+
4
28+
5
29+
```
30+
31+
# Bug 2
32+
33+
### code
34+
```
35+
var top10Movies = [
36+
'AI',
37+
'Shawshank Redemption',
38+
'Godfather',
39+
'Pulp Fiction',
40+
'Fight club',
41+
'Forrest Gump',
42+
'Inception',
43+
'Goodfellas',
44+
'The Matrix',
45+
'Interstellar'
46+
]
47+
var top10Actors = [
48+
'Marlon Brando',
49+
'Jack Nickolson',
50+
'Robert De Niro',
51+
'Al Pacino',
52+
'Daniel Day-Lewis',
53+
'Duston Hoffman',
54+
'Tom Hanks',
55+
'Anthony Hopkins',
56+
'Paul Newman',
57+
'Denzel Washington'
58+
59+
]
60+
61+
//just want to get all movies except top 3
62+
var index = 3;
63+
for (index; index < top10Movies.length; index++) {
64+
console.log('movie: ', top10Movies[index])
65+
}
66+
//also want to get all actors except top 3
67+
for (index; index < top10Actors; index++) {
68+
console.log('actor: ' + top10Actors[index])
69+
}
70+
71+
72+
```
73+
74+
### actual output:
75+
```
76+
movie: Pulp Fiction
77+
movie: Fight club
78+
movie: Forrest Gump
79+
movie: Inception
80+
movie: Goodfellas
81+
movie: The Matrix
82+
movie: Interstellar
83+
84+
```
85+
### expected output:
86+
```
87+
movie: Pulp Fiction
88+
movie: Fight club
89+
movie: Forrest Gump
90+
movie: Inception
91+
movie: Goodfellas
92+
movie: The Matrix
93+
movie: Interstellar
94+
actor: Al Pacino
95+
actor: Daniel Day-Lewis
96+
actor: Duston Hoffman
97+
actor: Tom Hanks
98+
actor: Anthony Hopkins
99+
actor: Paul Newman
100+
actor: Denzel Washington
101+
```

0 commit comments

Comments
 (0)