-
Notifications
You must be signed in to change notification settings - Fork 0
/
bug-hunt-solution.js
53 lines (42 loc) · 1.45 KB
/
bug-hunt-solution.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
const caterpillar = '🐛'; // missing quotes
const leaf = '🌿';
const rock = '🪨'; // mismatched quotes
let forest = ""; // needs to be let since we add to it
/*
FOR LOOP ISSUES:
Let vs const
needs semi-colons not commas
*/
for (let i = 0; i < 100; i++) {
if (Math.random() < 0.8) { // missing parens
forest += leaf;
} else {
forest += rock;
}
}
console.log(forest); // incorrect spelling
let numLeaves = 0; // needs to be let since we add to it
for (const emoji of forest) {
if (emoji == leaf) { // == for comparison, leaf not leave
numLeaves += 1; // should be +=1 not =+1
}
} // missing closing bracket
console.log(`There are ${numLeaves} leaves in the forest.`); // log not l0g
if (numLeaves >= 80) {
console.log("There are enough leaves to eat :)"); // missing closing paren
} else { // adding curley brackets around else statement
console.log("There are not enough leaves to eat :("); // console missing 'e', missing open paren
console.log(`${caterpillar} is hungry...`); // change to string literal with `
process.exit();
}
const timerLabel = `${caterpillar} ate all the leaves in`;
console.time(timerLabel);
console.log(`${caterpillar} gets to feast!`); // spelling error on variable name
let leafLog = ""; // needs to be let
while (numLeaves > 0) {
leafLog += `${numLeaves}.. `;
numLeaves -= 1; // (not =-)
}
console.log(leafLog); // typo
console.log('0! YUM!'); // mismatch quotes
console.timeEnd(timerLabel);