Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b0f8b3d

Browse files
committed
Week2 prep exercies solutions
1 parent fddf32a commit b0f8b3d

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

Week1/practice-exercises/4-reading-list.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,18 @@
99
* If you haven't read it log a string like You still need to read "The Lord of the Rings"
1010
*/
1111

12+
let books = [
13+
{ title: "The Hobbit", author: "J.R.R. Tolkien", alreadyRead: true },
14+
{ title: "1984", author: "George Orwell", alreadyRead: false },
15+
{ title: "To Kill a Mockingbird", author: "Harper Lee", alreadyRead: true }
16+
];
17+
18+
for (let book of books) {
19+
console.log(`${book.title} by ${book.author}`);
20+
21+
if (book.alreadyRead) {
22+
console.log(`You already read "${book.title}"`);
23+
} else {
24+
console.log(`You still need to read "${book.title}"`);
25+
}
26+
}

Week1/prep-exercises/1-traffic-light/traffic-light-2.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,17 @@ while (cycle < 2) {
1818
// if the color is green, turn it orange
1919
// if the color is orange, turn it red
2020
// if the color is red, add 1 to cycles and turn it green
21+
22+
if (currentState === "green") {
23+
trafficLight.stateIndex = 1; // Turn it on orange
24+
}
25+
else if (currentState === "orange") {
26+
trafficLight.stateIndex === 2; // Turn it on red
27+
}
28+
else if (currentState === "red") {
29+
trafficLight.stateIndex = 0; // Turn it on green
30+
cycle++;
31+
}
2132
}
2233

2334
/**

0 commit comments

Comments
 (0)