Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
node_modules
**/node_modules
.DS_Store
**/.DS_Store
**/.DS_StoreModule-Data-Flows/
Project-TV-Show/
2 changes: 2 additions & 0 deletions Module-Data-Flows/.github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github: CodeYourFuture
custom: https://codeyourfuture.io/donate
18 changes: 18 additions & 0 deletions Module-Data-Flows/.github/workflows/validate-pr-metadata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Validate PR Metadata
on:
pull_request_target:
types:
- labeled
- unlabeled
- opened
- edited
- reopened

jobs:
validate_pr_metadata:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: CodeYourFuture/actions/validate-pr-metadata@main
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4 changes: 4 additions & 0 deletions Module-Data-Flows/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
**/node_modules
.DS_Store
**/.DS_Store
19 changes: 19 additions & 0 deletions Module-Data-Flows/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"arrowParens": "always",
"bracketSpacing": true,
"embeddedLanguageFormatting": "auto",
"htmlWhitespaceSensitivity": "css",
"insertPragma": false,
"jsxBracketSameLine": false,
"jsxSingleQuote": false,
"printWidth": 80,
"proseWrap": "preserve",
"quoteProps": "as-needed",
"requirePragma": false,
"semi": true,
"singleQuote": false,
"tabWidth": 2,
"trailingComma": "es5",
"useTabs": false,
"vueIndentScriptAndStyle": false
}
10 changes: 10 additions & 0 deletions Module-Data-Flows/.vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"recommendations": [
"esbenp.prettier-vscode",
"dbaeumer.vscode-eslint",
"streetsidesoftware.code-spell-checker",
"eamodio.gitlens",
"ritwickdey.LiveServer",
"vsliveshare.vsliveshare"
]
}
17 changes: 17 additions & 0 deletions Module-Data-Flows/HOW-TO-GET-HELP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# How To Get Help

Learning to ask good questions is a key skill for a developer and you should practice this every week at CYF. You must spend a lot of time learning how to describe problems clearly and systematically:

https://curriculum.codeyourfuture.io/guides/asking-questions

Problem-solving is the real (marketable) skill of software developers. If you do not have questions to ask about your work, ask for some different work. Don't miss this opportunity to break down challenging problems with a large team of developers.

## Reporting Issues in Coursework

- Is there a problem with this coursework?
- Have you noticed a bug?
- Is there a typo or a mistake you can help clean up?

Open an issue or PR directly to the main repo. CYF Curriculum is an Open Source project developed on GitHub and you are invited to contribute. Read the Issue Template carefully.

https://github.com/CodeYourFuture/curriculum/
15 changes: 15 additions & 0 deletions Module-Data-Flows/Sprint-1/destructuring/exercise-1/exercise.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const personOne = {
name: "Popeye",
age: 34,
favouriteFood: "Spinach",
};

// Update the parameter to this function to make it work.
// Don't change anything else.
function introduceYourself(___________________________) {
console.log(
`Hello, my name is ${name}. I am ${age} years old and my favourite food is ${favouriteFood}.`
);
}

introduceYourself(personOne);
33 changes: 33 additions & 0 deletions Module-Data-Flows/Sprint-1/destructuring/exercise-1/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
We can use object destructuring to extract values from an object and assign them to variables in one line.

```js
let person = {
firstName: "Bruce",
lastName: "Wayne",
};

let { firstName, lastName } = person;

console.log(`Batman is ${firstName}, ${lastName}`);
```

The program above will print `Batman is Bruce Wayne`.

This is more concise than doing this without object destructuring:

```js
let person = {
firstName: "Bruce",
lastName: "Wayne",
};

let firstName = person.firstName;
let lastName = person.lastName;

console.log(`Batman is ${firstName}, ${lastName}`);
```

# Exercise

- What is the syntax to destructure the object `personOne` in exercise.js?
- Update the parameter of the function `introduceYourself` to use destructuring on the object that gets passed in.
72 changes: 72 additions & 0 deletions Module-Data-Flows/Sprint-1/destructuring/exercise-2/exercise.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
let hogwarts = [
{
firstName: "Harry",
lastName: "Potter",
house: "Gryffindor",
pet: "Owl",
occupation: "Student",
},
{
firstName: "Ron",
lastName: "Weasley",
house: "Gryffindor",
pet: "Scabbers",
occupation: "Student",
},
{
firstName: "Hermione",
lastName: "Granger",
house: "Gryffindor",
pet: "Cat",
occupation: "Student",
},
{
firstName: "Draco",
lastName: "Malfoy",
house: "Slytherin",
pet: null,
occupation: "Student",
},
{
firstName: "Cedric",
lastName: "Diggory",
house: "HufflePuff",
pet: null,
occupation: "Student",
},
{
firstName: "Severus",
lastName: "Snape",
house: "Slytherin",
pet: null,
occupation: "Teacher",
},
{
firstName: "Filius",
lastName: "Flitwick",
house: "Ravenclaw",
pet: null,
occupation: "Teacher",
},
{
firstName: "Pomona",
lastName: "Sprout",
house: "Hufflepuff",
pet: null,
occupation: "Teacher",
},
{
firstName: "Minerva",
lastName: "McGonagall",
house: "Gryffindor",
pet: null,
occupation: "Teacher",
},
{
firstName: "Albus",
lastName: "Dumbledore",
house: "Gryffindor",
pet: "Phoenix",
occupation: "Teacher",
},
];
37 changes: 37 additions & 0 deletions Module-Data-Flows/Sprint-1/destructuring/exercise-2/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Exercise 2

In `exercise.js`, you have an array that contains a list of people who are at Hogwarts School of Witchcraft and Wizardry.

For each character you have the following information:

- First Name
- Last Name
- School House
- Pet
- Occupation

## Task 1

- In `exercise.js` write a program that will take the `hogwarts` array as input and display the names of the people who belong to the Gryffindor house.
- Use object destructuring to extract the values you need out of each element in the array.

### Expected result

```
Harry Potter
Ron Weasley
Hermione Granger
Minerva McGonagall
Albus Dumbledore
```

## Task 2

- In `exercise.js` write a program that will take the `hogwarts` array as input and display the names of teachers who have pets.
- Use object destructuring to extract the values you need out of each element in the array.

### Expected result

```
Albus Dumbledore
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
let order = [
{ itemName: "Hot cakes", quantity: 1, unitPricePence: 232 },
{ itemName: "Apple Pie", quantity: 2, unitPricePence: 139 },
{ itemName: "Egg McMuffin", quantity: 1, unitPricePence: 280 },
{ itemName: "Sausage McMuffin", quantity: 1, unitPricePence: 300 },
{ itemName: "Hot Coffee", quantity: 2, unitPricePence: 100 },
{ itemName: "Hash Brown", quantity: 4, unitPricePence: 40 },
];
21 changes: 21 additions & 0 deletions Module-Data-Flows/Sprint-1/destructuring/exercise-3/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Exercise

- In `exercise.js`, you have been provided with a takeout order. Write a program that will print out the receipt for this order.
- Log each individual item to the console.
- Log the total cost of the order to the console.
- Use object destructuring to access the values you need from each item.
- Pay attention to the exact formatting of the expected result.

## Expected result

```
QTY ITEM TOTAL
1 Hot Cakes 2.32
2 Apple Pie 2.78
1 Egg McMuffin 2.80
1 Sausage McMuffin 3.00
2 Hot Coffee 2.00
4 Hash Brown 1.60

Total: 14.50
```
52 changes: 52 additions & 0 deletions Module-Data-Flows/challenges/challenge-cowsay-two/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Cowsay

Cowsay is a fun script that prints an [ASCII](https://simple.wikipedia.org/wiki/ASCII) cow with your words in a speech bubble. It works like this: there is a library of pictures of cows made out of ASCII characters. You call the script in your terminal and you pass in arguments. There are lots of options, but one argument is required: a text string for the cow to say.

```
 ________
< Mooooo >
 --------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

```

Cowsay was originally written in [Perl](https://simple.wikipedia.org/wiki/Perl), but has been written in many other programming languages too. In this coursework, we will write it in JavaScript.

## Project

Let's get one cow printing out and saying whatever we write in the command line. What would be helpful? I think we need to:

- [Accept an argument](https://nodejs.dev/learn/nodejs-accept-arguments-from-the-command-line) from the command line.
- Output to the command line. You've already done this with console.log.
- Make an ASCII cow.
- Write a function that puts the string into the cow's speech bubble.

Write your solution in the file solution1.js and test it by running your program in the command line. How will you handle it when no argument is given? How will you make the picture of a cow?

### Iterating

We could make our program more accessible by adding a command line interface that prompts us to write in the cow's words. What tools can we use? I think we could use:

- A command line interface. I'll start you off by letting you know that there is a built in CLI called [readline](https://nodejs.dev/learn/accept-input-from-the-command-line-in-nodejs).
- Our ASCII cow again.
- And our cow function.

Write your solution in a file called solution2.js and test it by running your program in the command line. Use a prompt to ask for your cow saying.

Compare your approach to the sample solutions (you can unlock next week). Your solution might be different and that's ok. If you can print a cow and you can make it say different things, you solved it.

A slightly simpler ASCII cow that might help if you hit formatting issues.

```
/
/
^__^ /
(oo)'_______
(__) )-~
||----w |
|| ||
```
30 changes: 30 additions & 0 deletions Module-Data-Flows/challenges/challenge-cowsay-two/solution1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// =================
// Stripped down cowsayer CLI,
// no libraries
// https://nodejs.dev/learn/nodejs-accept-arguments-from-the-command-line
// =================

// 1. Accept arguments

// how will you accept arguments?

// 2. Make supplies for our speech bubble

let topLine = '_';
let bottomLine = '-';
let saying = '';

// 3. Make a cow that takes a string

function cowsay(saying) {
// how will you make the speech bubble contain the text?

// where will the cow picture go?

// how will you account for the parameter being empty?

}

//4. Pipe argument into cowsay function and return a cow

// how will you log this to the console?
18 changes: 18 additions & 0 deletions Module-Data-Flows/challenges/challenge-cowsay-two/solution2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// =================
// Stripped down cowsayer CLI,
// no libraries or arguments
// https://nodejs.dev/learn/accept-input-from-the-command-line-in-nodejs
// =================

// 1. Make a command line interface.

// 2. Make supplies for our speech bubble

// 3. Make a cow that takes a string

const cow = (saying) => {
// how did you make the cow before?
}

// 4. Use readline to get a string from the terminal
// (with a prompt so it's clearer what we want)
Loading
Loading