Skip to content

Commit d221b09

Browse files
Merge branch 'code-differently:main' into evan_03
2 parents 6e2600a + 904cb45 commit d221b09

File tree

4 files changed

+103
-37
lines changed

4 files changed

+103
-37
lines changed

lesson_03/quiz/src/lesson3.test.ts

Lines changed: 41 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -80,52 +80,57 @@ describe('Lesson3Test', () => {
8080
maybeIt(
8181
'checks multiple choice answers are configured correctly',
8282
async () => {
83-
for (const [providerName, questions] of quizQuestionsByProvider) {
84-
for (const question of questions) {
85-
if (!(question instanceof MultipleChoiceQuizQuestion)) {
86-
continue;
87-
}
88-
89-
// Assert that multiple choice questions have at least one correct answer.
90-
const choices = question.getAnswerChoices();
91-
const areAnswersValid = await Promise.all(
92-
[...choices].map(async (choice) => {
93-
return quizConfig.checkAnswer(
94-
providerName,
95-
question.getQuestionNumber(),
96-
choice,
97-
);
98-
}),
99-
);
100-
101-
expect(areAnswersValid.some((isCorrect) => isCorrect)).toBe(true);
83+
const { providerName, questions } = getQuestionsFromCurrentProvider();
84+
for (const question of questions) {
85+
if (!(question instanceof MultipleChoiceQuizQuestion)) {
86+
continue;
10287
}
88+
89+
// Assert that multiple choice questions have at least one correct answer.
90+
const choices = question.getAnswerChoices();
91+
const areAnswersValid = await Promise.all(
92+
[...choices].map(async (choice) => {
93+
return quizConfig.checkAnswer(
94+
providerName,
95+
question.getQuestionNumber(),
96+
choice,
97+
);
98+
}),
99+
);
100+
101+
expect(areAnswersValid.some((isCorrect) => isCorrect)).toBe(true);
103102
}
104103
},
105104
);
106105

107106
maybeIt('checks for correct answers', async () => {
107+
const { providerName, questions } = getQuestionsFromCurrentProvider();
108+
for (const question of questions) {
109+
const actualAnswer = question.getAnswer();
110+
softExpect(actualAnswer).not.toBe(AnswerChoice.UNANSWERED);
111+
softExpect(
112+
await quizConfig.checkAnswer(
113+
providerName,
114+
question.getQuestionNumber(),
115+
actualAnswer,
116+
),
117+
).toBe(true);
118+
}
119+
});
120+
121+
function getQuestionsFromCurrentProvider(): {
122+
providerName: string;
123+
questions: QuizQuestion[];
124+
} {
108125
const targetProviderName = process.env.PROVIDER_NAME?.trim() || '';
109126

110127
if (!quizQuestionsByProvider.has(targetProviderName)) {
111128
throw new Error(`Unknown provider name: ${targetProviderName}`);
112129
}
113130

114-
for (const [providerName, questions] of quizQuestionsByProvider) {
115-
if (providerName !== process.env.PROVIDER_NAME?.trim()) {
116-
continue;
117-
}
118-
for (const question of questions) {
119-
const actualAnswer = question.getAnswer();
120-
softExpect(actualAnswer).not.toBe(AnswerChoice.UNANSWERED);
121-
softExpect(
122-
await quizConfig.checkAnswer(
123-
providerName,
124-
question.getQuestionNumber(),
125-
actualAnswer,
126-
),
127-
).toBe(true);
128-
}
129-
}
130-
});
131+
return {
132+
providerName: targetProviderName,
133+
questions: quizQuestionsByProvider.get(targetProviderName) || [],
134+
};
135+
}
131136
});

lesson_04/README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,9 @@ Please review the following resources before lecture:
99

1010
## Homework
1111

12-
- TODO(anthonydmays): Provide details
12+
- [ ] Do [coding exercise](#writing-some-code).
13+
- [ ] Do pre-work for [lesson 05](/lesson_05/).
14+
15+
### Writing some code
16+
17+
For this assignment, you will need to write code that determines whether a number is a prime number. You will produce code in two different languages, then provide a 100+ word write up about the similarities and differences between the two implementations you made. An example is provided in the [anthonydmays/](./anthonydmays/) folder.

lesson_04/anthonydmays/README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
## Python implementation
2+
3+
```python
4+
def is_even(number):
5+
return number % 2 == 0
6+
7+
# Example usage:
8+
print(is_even(4)) # Output: True
9+
print(is_even(7)) # Output: False
10+
```
11+
12+
## JavaScript implementation
13+
14+
```javascript
15+
function isEven(number) {
16+
return number % 2 === 0;
17+
}
18+
19+
// Example usage:
20+
console.log(isEven(4)); // Output: true
21+
console.log(isEven(7)); // Output: false
22+
```
23+
24+
## Explanation
25+
26+
The Python implementation uses a function named `is_even` that takes a single argument `number`. It returns `True` if the number is even (i.e., when the remainder of the division of the number by 2 is zero), otherwise, it returns `False`.
27+
28+
The JavaScript implementation uses a function named `isEven` that also takes a single argument `number`. It returns `true` if the number is even (using the same logic as the Python function) and `false` otherwise.
29+
30+
### Differences
31+
32+
1. **Syntax**:
33+
- In Python, functions are defined using the `def` keyword, whereas in JavaScript, the `function` keyword is used.
34+
- Python uses `True` and `False` for boolean values, while JavaScript uses `true` and `false`.
35+
36+
2. **Type Coercion**:
37+
- JavaScript has type coercion, which can sometimes lead to unexpected results if the input is not properly handled. In contrast, Python is more strict with types.
38+
39+
3. **Function Calls**:
40+
- The syntax for calling functions and printing to the console/output is slightly different. Python uses `print()`, while JavaScript uses `console.log()`.

lesson_05/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Lesson 05: Software Development Life Cycle ([Slides](https://code-differently.github.io/code-differently-24-q4/slides/#/lesson_05))
2+
3+
## Pre-work
4+
5+
Please review the following resources before lecture:
6+
7+
### Required
8+
* [Software Development Life Cycle: Explained (Video)](https://www.youtube.com/watch?v=SaCYkPD4_K0)
9+
* [What is the "best way" to develop software applications? (Video)](https://www.youtube.com/watch?v=oNmcX6Gozg0)
10+
11+
### Recommended
12+
* [User stories with examples and a template](https://www.atlassian.com/agile/project-management/user-stories)
13+
14+
## Homework
15+
16+
- TODO(anthonydmays): Write details here.

0 commit comments

Comments
 (0)