Skip to content

Commit 1e69348

Browse files
author
Anna Aitchison
committed
Add in the questions-and-reviews workshop
1 parent 06edab3 commit 1e69348

11 files changed

Lines changed: 131 additions & 0 deletions

File tree

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Code comprehension
2+
3+
Remember to **preview a markdown file** on your computer you can do:
4+
Ctrl + Shift + V (Windows/Linux) or CMD + Shift + V (Mac)
5+
6+
Consider the code in this program below:
7+
8+
```js
9+
function calculateSum(a, b) {
10+
return a + b;
11+
}
12+
13+
function logSum(a, b) {
14+
console.log(a + b);
15+
}
16+
17+
const result1 = calculateSum(10, 32);
18+
const result2 = logSum(10, 32);
19+
```
20+
21+
a) what will `result1` evaluate to? Explain your answer
22+
23+
b) What will `result2` evaluate to? Explain your answer
24+
25+
c) Try to summarise the main difference between `logSum` and `calculateSum`
26+
27+
28+
{YOUR ANSWERS HERE}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// IMPORTANT: Please read 1.md first!
2+
// Remember to write your prediction first, before you run this file
3+
4+
const currentYear = 2023;
5+
currentYear();
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Predict => Run => Observe => Explain
2+
3+
Remember to **preview a markdown file** on your computer you can do:
4+
Ctr + Shift + V (Windows/Linux) or CMD + Shift + V (Mac)
5+
6+
In this task, you'll need to look at some code in `1.js` and, firstly, predict what it will do, **without executing it**.
7+
8+
{YOUR PREDICTION HERE}
9+
10+
Afterwards, you can execute the code in `1.js` to check your answer 📝
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// IMPORTANT: Read 2.md first before using this file!
2+
// ## Predict -> Run -> Observe -> Explain
3+
4+
let count = 0;
5+
6+
while(count < 10) {
7+
count++;
8+
console.log('*'.repeat(count))
9+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
## Predict -> Run -> Observe -> Explain
2+
3+
In this task, you'll need to look at some code and predict what it does, **before running the program**
4+
This task will help you to develop your code reading skills.
5+
6+
7+
Look at the code in `2.js`: read it carefully and discuss it with your pair.
8+
What do you think the output will look like?
9+
If some parts of the code are unfamiliar, then look them up on MDN.
10+
Write your prediction below:
11+
12+
{YOUR PREDICTION HERE}
13+
14+
Once you've written your prediction, then commit your work. Now actually run `2.js` using node and write your answer below:
15+
16+
{ACTUAL OBSERVED BEHAVIOUR}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Describe the difference between a commit and a push
2+
3+
4+
{YOUR ANSWER HERE}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Q: What is the difference between a fork and cloned repository?
2+
3+
A: {YOUR ANSWER HERE}
4+
5+
6+
Remember to commit and push when you're finished!
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
You've started to see **assertions** in your coursework that look something like this:
3+
4+
```js
5+
expect(sum(10,32)).toBe(42);
6+
```
7+
8+
a) Describe, in your own words, what the above assertion checks.
9+
10+
Now try the following:
11+
12+
b) Write an **assertion** that checks that a function `isMultipleOfTen` returns `true` when called with the input `80`
13+
You can check out the [Jest documentation here](https://jestjs.io/docs/expect#matchers) to help you with this task.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
3+
4+
5+
function printTimesTables(n) {
6+
const count = 1;
7+
while(count <= 12) {
8+
const product = n * i;
9+
console.log(`${n} * ${i} = ${product}`);
10+
count++;
11+
}
12+
}
13+
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
## To err is human ( Trickier )
2+
3+
4+
Consider the function `printTimesTable` defined in `6.js`.
5+
6+
This function should behave in the following manner:
7+
when invoked with a number, say 5, it should print the 5 times table, from 1 to 12, on each line:
8+
9+
10+
```
11+
1 * 5 = 5
12+
2 * 5 = 10
13+
3 * 5 = 15
14+
.
15+
.
16+
.
17+
11 * 5 = 55
18+
12 * 5 = 60
19+
```
20+
21+
However, the current implementation isn't working. In fact, it's actually throwing errors 😱!
22+
Try invoking the function in `6.js` and see if you can identify exactly what type of error is occuring and where it originated ( which line of code).
23+
24+
Learning to love your error messages is an absolutely critical skill - best to get used to it early on.

0 commit comments

Comments
 (0)