Skip to content

Commit c8ff2fe

Browse files
committed
populate module from js2
1 parent a02c613 commit c8ff2fe

File tree

117 files changed

+13943
-37
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

117 files changed

+13943
-37
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules
2+
.DS_Store
3+
.vscode
4+
**/.DS_Store

.prettierrc

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"arrowParens": "always",
3+
"bracketSpacing": true,
4+
"embeddedLanguageFormatting": "auto",
5+
"htmlWhitespaceSensitivity": "css",
6+
"insertPragma": false,
7+
"jsxBracketSameLine": false,
8+
"jsxSingleQuote": false,
9+
"printWidth": 80,
10+
"proseWrap": "preserve",
11+
"quoteProps": "as-needed",
12+
"requirePragma": false,
13+
"semi": true,
14+
"singleQuote": false,
15+
"tabWidth": 2,
16+
"trailingComma": "es5",
17+
"useTabs": false,
18+
"vueIndentScriptAndStyle": false
19+
}

Example-Image.jpeg

-910 KB
Binary file not shown.

HOW_TO_REVIEW.md

+4-18
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
<!--
2-
Do not edit this file.
3-
Make a change to the template and then pull changes
4-
Repo: https://github.com/CodeYourFuture/Module-Template
5-
-->
6-
71
# Everyone reviews code at CYF
82

3+
https://curriculum.codeyourfuture.io/guides/reviewing/
4+
95
Mentors and trainees all review code, and collaborate on improving code quality. We are all helping each other to talk, write, and think about code more clearly.
106

117
We are not reviewing code as if we were to merge this PR into production; we are opening a technical conversation for the purpose of insight and development.
@@ -35,7 +31,7 @@ Reviewers, please add labels (provided) to the PR once you've reviewed. This hel
3531

3632
### Where to find solutions?
3733

38-
You can find the solutions for the module on the `solutions` branch.
34+
You can find the solutions for the module on the `solutions` branch. If there is no solutions branch, it's because no one has written one yet. Could you do this?
3935

4036
### Solutions branch
4137

@@ -53,14 +49,4 @@ Use these resources to inform your code review, get unstuck, and improve your un
5349

5450
## Guides
5551

56-
Here's a detailed checklist of the sorts of things we should check code for:
57-
58-
https://syllabus.codeyourfuture.io/guides/marking-guide
59-
60-
Here's a detailed style guide to help us all write clear, high quality code:
61-
62-
https://syllabus.codeyourfuture.io/guides/code-style-guide
63-
64-
Here's some help with giving good feedback during code review:
65-
66-
https://teachertraining.codeyourfuture.io/tasks/code-review
52+
https://curriculum.codeyourfuture.io/guides/reviewing/

accessing-values/bracket-notation.js

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
You can also access the value of a property using bracket notation.
3+
Bracket notation can be used when the property is stored as the value of a variable.
4+
This can be very useful for iterating through an object's properties or when accessing a lookup table.
5+
*/
6+
7+
let capitalCities = {
8+
UnitedKingdom: "London",
9+
China: "Beijing",
10+
Peru: "Lima",
11+
};
12+
13+
/*
14+
You have an object, capitalCities, that contains key/value pairs of countries and their capital cities.
15+
Log the value for the property assigned to the variable myCountry using bracket notation.
16+
Do not use dot notation for this exercise!
17+
*/
18+
19+
let myCountry = "UnitedKingdom";
20+
let myCapitalCity; // complete the code
21+
22+
console.log(myCapitalCity);
23+
24+
/* EXPECTED RESULT
25+
26+
London
27+
28+
*/

accessing-values/dot-notation.js

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
This object has 4 properties
3+
The properties of the object are all primitive types (string, number or boolean)
4+
What is the type of each property?
5+
*/
6+
7+
let dog = {
8+
breed: "Dalmatian",
9+
name: "Spot",
10+
isHungry: true,
11+
happiness: 6,
12+
};
13+
14+
/*
15+
You can access the values of each property using dot notation.
16+
Log the name and breed of this dog using dot notation.
17+
*/
18+
19+
let dogName; // complete the code
20+
let dogBreed; // complete the code
21+
22+
console.log(`${dogName} is a ${dogBreed}`);
23+
24+
/* EXPECTED RESULT
25+
26+
Spot is a Dalmatian
27+
28+
*/

accessing-values/readme.md

+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
## Accessing Values
2+
3+
<!--```objectives
4+
- Access values in an object using dot notation
5+
- Find the type of a value
6+
```
7+
-->
8+
9+
### What is the type of each property?
10+
11+
This object has 4 properties. The properties of the object are all primitive types (string, number or boolean).
12+
13+
```js
14+
let dog = {
15+
breed: "Dalmatian",
16+
name: "Spot",
17+
isHungry: true,
18+
happiness: 6,
19+
};
20+
```
21+
22+
## Log the name and breed of this dog using dot notation.
23+
24+
You can access the values of each property using dot notation.
25+
26+
```js
27+
let dogName; // complete the code
28+
let dogBreed; // complete the code
29+
30+
console.log(`${dogName} is a ${dogBreed}`);
31+
```
32+
33+
### Expected Output
34+
35+
> `Spot is a Dalmatian`
36+
37+
## Accessing Object Properties
38+
39+
<!--```objectives
40+
- Access object properties using bracket notation
41+
- Use a variable as a key to access an object's property
42+
```-->
43+
44+
### What is bracket notation?
45+
46+
You can also access the value of a property using bracket notation. Bracket notation can be used when the property is stored as the value of a variable. This can be very useful for iterating through an object's properties or when accessing a lookup table.
47+
48+
```js
49+
let capitalCities = {
50+
UnitedKingdom: "London",
51+
China: "Beijing",
52+
Peru: "Lima",
53+
};
54+
```
55+
56+
## Working with Complex Objects
57+
58+
<!--```objectives
59+
- Access properties of nested objects and arrays within an object
60+
- Sort an array of strings
61+
- Use console.log to print multiple lines
62+
```-->
63+
64+
### Objects with nested properties
65+
66+
An object's properties can have values that are other objects or arrays.
67+
68+
```js
69+
let basketballTeam = {
70+
name: "Chicago Bulls",
71+
numberOfPlayers: 15,
72+
topPlayers: ["Michael Jordan", "Scottie Pippen", "Dennis Rodman"],
73+
homeStadium: {
74+
name: "United Center",
75+
capacity: 21000,
76+
address: "1901 W Madison St",
77+
},
78+
};
79+
```
80+
81+
## Access and manipulate properties
82+
83+
### Write code that:
84+
85+
- [ ] accesses the basketball team's top players array
86+
- [ ] sorts the top players in alphabetical order
87+
- [ ] logs the name of each player on a new line
88+
89+
```js
90+
// Write your code here
91+
```
92+
93+
### Expected Output
94+
95+
```
96+
Dennis Rodman
97+
Michael Jordan
98+
Scottie Pippen
99+
```
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
An object's properties can have values that are other objects or arrays.
3+
*/
4+
5+
let basketballTeam = {
6+
name: "Chicago Bulls",
7+
numberOfPlayers: 15,
8+
topPlayers: ["Michael Jordan", "Scottie Pippen", "Dennis Rodman"],
9+
homeStadium: {
10+
name: "United Center",
11+
capacity: 21000,
12+
address: "1901 W Madison St",
13+
},
14+
};
15+
16+
/*
17+
Write code that
18+
- accesses the basketball team's top players array
19+
- sorts the top players in alphabetical order
20+
- console.logs the name of each player on a new line
21+
*/
22+
23+
// write code here
24+
25+
/* EXPECTED RESULT
26+
27+
Dennis Rodman
28+
Michael Jordan
29+
Scottie Pippen
30+
31+
*/

alarmclock/alarmclock.js

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
function setAlarm() {}
2+
3+
// DO NOT EDIT BELOW HERE
4+
5+
var audio = new Audio("alarmsound.mp3");
6+
7+
function setup() {
8+
document.getElementById("set").addEventListener("click", () => {
9+
setAlarm();
10+
});
11+
12+
document.getElementById("stop").addEventListener("click", () => {
13+
pauseAlarm();
14+
});
15+
}
16+
17+
function playAlarm() {
18+
audio.play();
19+
}
20+
21+
function pauseAlarm() {
22+
audio.pause();
23+
}
24+
25+
window.onload = setup;

alarmclock/alarmclock.test.js

+104
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/* ======= TESTS - READ CAREFULLY =====
2+
There are some Tests in this file that will help you work out if your code is working.
3+
*/
4+
5+
const path = require("path");
6+
const { JSDOM } = require("jsdom");
7+
8+
let page = null;
9+
10+
beforeEach(async () => {
11+
page = await JSDOM.fromFile(path.join(__dirname, "index.html"), {
12+
resources: "usable",
13+
runScripts: "dangerously",
14+
});
15+
16+
jest.useFakeTimers();
17+
18+
// do this so students can use element.innerText which jsdom does not implement
19+
Object.defineProperty(page.window.HTMLElement.prototype, "innerText", {
20+
get() {
21+
return this.textContent;
22+
},
23+
set(value) {
24+
this.textContent = value;
25+
},
26+
});
27+
28+
return new Promise((res) => {
29+
page.window.document.addEventListener("load", res);
30+
});
31+
});
32+
33+
afterEach(() => {
34+
jest.useRealTimers();
35+
page = null;
36+
});
37+
38+
test("should set heading when button is clicked", () => {
39+
const heading = page.window.document.querySelector("#timeRemaining");
40+
const input = page.window.document.querySelector("#alarmSet");
41+
const button = page.window.document.querySelector("#set");
42+
43+
input.value = "19";
44+
button.click();
45+
46+
expect(heading).toHaveTextContent("Time Remaining: 00:19");
47+
});
48+
49+
test("should split values over 60 seconds into minutes and seconds", () => {
50+
const heading = page.window.document.querySelector("#timeRemaining");
51+
const input = page.window.document.querySelector("#alarmSet");
52+
const button = page.window.document.querySelector("#set");
53+
54+
input.value = "119";
55+
button.click();
56+
57+
expect(heading).toHaveTextContent("Time Remaining: 01:59");
58+
});
59+
60+
test("should update the heading while counting down", () => {
61+
const heading = page.window.document.querySelector("#timeRemaining");
62+
const input = page.window.document.querySelector("#alarmSet");
63+
const button = page.window.document.querySelector("#set");
64+
65+
input.value = "19";
66+
button.click();
67+
68+
for (let i = 18; i > 0; i--) {
69+
jest.runOnlyPendingTimers();
70+
const seconds = `${i}`.padStart(2, "0");
71+
expect(heading).toHaveTextContent(`Time Remaining: 00:${seconds}`);
72+
}
73+
});
74+
75+
test("should count down every 1000 ms", () => {
76+
const input = page.window.document.querySelector("#alarmSet");
77+
const button = page.window.document.querySelector("#set");
78+
79+
const mockTimer = jest.fn();
80+
page.window.setTimeout = mockTimer;
81+
page.window.setInterval = mockTimer;
82+
83+
input.value = "19";
84+
button.click();
85+
86+
expect(mockTimer).toHaveBeenCalledTimes(1);
87+
expect(mockTimer).toHaveBeenLastCalledWith(expect.any(Function), 1000);
88+
});
89+
90+
test("should play audio when the timer reaches zero", () => {
91+
const input = page.window.document.querySelector("#alarmSet");
92+
const button = page.window.document.querySelector("#set");
93+
const mockPlayAlarm = jest.fn();
94+
95+
page.window.playAlarm = mockPlayAlarm;
96+
input.value = "10";
97+
button.click();
98+
99+
expect(mockPlayAlarm).toHaveBeenCalledTimes(0);
100+
101+
jest.runAllTimers();
102+
103+
expect(mockPlayAlarm).toHaveBeenCalledTimes(1);
104+
});

alarmclock/alarmsound.mp3

265 KB
Binary file not shown.

0 commit comments

Comments
 (0)