diff --git a/courses/backend/advanced-javascript/week1/data/teas.js b/courses/backend/advanced-javascript/week1/data/teas.js new file mode 100644 index 000000000..e7695b125 --- /dev/null +++ b/courses/backend/advanced-javascript/week1/data/teas.js @@ -0,0 +1,23 @@ +// prettier-ignore +export const teas = [ + { id: 1, name: "Sencha", type: "green", origin: "Japan", pricePerGram: 0.12, caffeineLevel: "medium", organic: true, inStock: true, stockCount: 150 }, + { id: 2, name: "Earl Grey", type: "black", origin: "India", pricePerGram: 0.08, caffeineLevel: "high", organic: false, inStock: true, stockCount: 200 }, + { id: 3, name: "Dragon Well", type: "green", origin: "China", pricePerGram: 0.25, caffeineLevel: "medium", organic: true, inStock: true, stockCount: 45 }, + { id: 4, name: "Chamomile", type: "herbal", origin: "Egypt", pricePerGram: 0.10, caffeineLevel: "none", organic: true, inStock: true, stockCount: 180 }, + { id: 5, name: "Darjeeling", type: "black", origin: "India", pricePerGram: 0.18, caffeineLevel: "high", organic: false, inStock: true, stockCount: 90 }, + { id: 6, name: "Oolong", type: "oolong", origin: "Taiwan", pricePerGram: 0.22, caffeineLevel: "medium", organic: true, inStock: true, stockCount: 60 }, + { id: 7, name: "Peppermint", type: "herbal", origin: "USA", pricePerGram: 0.08, caffeineLevel: "none", organic: true, inStock: true, stockCount: 220 }, + { id: 8, name: "Matcha", type: "green", origin: "Japan", pricePerGram: 0.45, caffeineLevel: "high", organic: true, inStock: true, stockCount: 30 }, + { id: 9, name: "Assam", type: "black", origin: "India", pricePerGram: 0.09, caffeineLevel: "high", organic: false, inStock: true, stockCount: 175 }, + { id: 10, name: "White Peony", type: "white", origin: "China", pricePerGram: 0.30, caffeineLevel: "low", organic: true, inStock: true, stockCount: 55 }, + { id: 11, name: "Rooibos", type: "herbal", origin: "South Africa", pricePerGram: 0.11, caffeineLevel: "none", organic: true, inStock: true, stockCount: 140 }, + { id: 12, name: "Gyokuro", type: "green", origin: "Japan", pricePerGram: 0.56, caffeineLevel: "high", organic: false, inStock: false, stockCount: 0 }, + { id: 13, name: "Lapsang Souchong", type: "black", origin: "China", pricePerGram: 0.15, caffeineLevel: "medium", organic: false, inStock: true, stockCount: 85 }, + { id: 14, name: "Silver Needle", type: "white", origin: "China", pricePerGram: 0.50, caffeineLevel: "low", organic: true, inStock: true, stockCount: 25 }, + { id: 15, name: "Genmaicha", type: "green", origin: "Japan", pricePerGram: 0.10, caffeineLevel: "low", organic: false, inStock: true, stockCount: 110 }, + { id: 16, name: "Tie Guan Yin", type: "oolong", origin: "China", pricePerGram: 0.30, caffeineLevel: "medium", organic: true, inStock: true, stockCount: 40 }, + { id: 17, name: "English Breakfast", type: "black", origin: "Sri Lanka", pricePerGram: 0.06, caffeineLevel: "high", organic: false, inStock: true, stockCount: 250 }, + { id: 18, name: "Hibiscus", type: "herbal", origin: "Sudan", pricePerGram: 0.09, caffeineLevel: "none", organic: true, inStock: true, stockCount: 95 }, + { id: 19, name: "Pu-erh", type: "black", origin: "China", pricePerGram: 0.35, caffeineLevel: "medium", organic: false, inStock: false, stockCount: 0 }, + { id: 20, name: "Jasmine Pearl", type: "green", origin: "China", pricePerGram: 0.32, caffeineLevel: "medium", organic: true, inStock: true, stockCount: 70 } +]; \ No newline at end of file diff --git a/courses/backend/advanced-javascript/week1/exercise-1.js b/courses/backend/advanced-javascript/week1/exercise-1.js new file mode 100644 index 000000000..3295d9e59 --- /dev/null +++ b/courses/backend/advanced-javascript/week1/exercise-1.js @@ -0,0 +1,3 @@ +import { teas } from "./data/teas.js"; + +teas.forEach(tea => console.log(tea.name)); \ No newline at end of file diff --git a/courses/backend/advanced-javascript/week1/exercise-10.js b/courses/backend/advanced-javascript/week1/exercise-10.js new file mode 100644 index 000000000..9d11419dc --- /dev/null +++ b/courses/backend/advanced-javascript/week1/exercise-10.js @@ -0,0 +1,3 @@ +import { teas } from "./data/teas.js"; + +const organicTeasInStock = teas.filter(tea => tea.inStock).filter(tea => tea.organic); \ No newline at end of file diff --git a/courses/backend/advanced-javascript/week1/exercise-11.js b/courses/backend/advanced-javascript/week1/exercise-11.js new file mode 100644 index 000000000..f6e706224 --- /dev/null +++ b/courses/backend/advanced-javascript/week1/exercise-11.js @@ -0,0 +1,3 @@ +import { teas } from "./data/teas.js"; + +const greenTeaNames = teas.filter(tea => tea.type === "green").map(tea => tea.name); \ No newline at end of file diff --git a/courses/backend/advanced-javascript/week1/exercise-12.js b/courses/backend/advanced-javascript/week1/exercise-12.js new file mode 100644 index 000000000..0da151a3c --- /dev/null +++ b/courses/backend/advanced-javascript/week1/exercise-12.js @@ -0,0 +1,3 @@ +import { teas } from "./data/teas.js"; + +const organicTeaStrings = teas.filter(tea => tea.organic).map(tea => `${tea.name} - ${tea.pricePerGram * 100} DKK/100g`); \ No newline at end of file diff --git a/courses/backend/advanced-javascript/week1/exercise-13.js b/courses/backend/advanced-javascript/week1/exercise-13.js new file mode 100644 index 000000000..9e6ad364b --- /dev/null +++ b/courses/backend/advanced-javascript/week1/exercise-13.js @@ -0,0 +1,3 @@ +import { teas } from "./data/teas.js"; + +const japaneseTeasByPrice = teas.filter(tea => tea.origin === "Japan").sort((a, b) => a.pricePerGram - b.pricePerGram); \ No newline at end of file diff --git a/courses/backend/advanced-javascript/week1/exercise-17.js b/courses/backend/advanced-javascript/week1/exercise-17.js new file mode 100644 index 000000000..fc2bce88e --- /dev/null +++ b/courses/backend/advanced-javascript/week1/exercise-17.js @@ -0,0 +1,25 @@ +// filterTeas(teas, { organic: true }); +// // Returns all organic teas + +// filterTeas(teas, { origin: "Japan" }); +// // Returns all Japanese teas + +// filterTeas(teas, { organic: true, origin: "Japan" }); +// // Returns organic Japanese teas + +// filterTeas(teas, { type: "green", inStock: true }); +// // Returns green teas that are in stock + +import { teas } from "./data/teas.js"; + +function filterTeas (teas, obj) { + const entries = Object.entries(obj); + entries.forEach((entry) => { + const key = entry[0]; + const value = entry[1]; + teas = teas.filter(tea => tea[key] === value); + }) + return teas; +} + +console.log(filterTeas(teas, { type: "green", inStock: true })); \ No newline at end of file diff --git a/courses/backend/advanced-javascript/week1/exercise-2.js b/courses/backend/advanced-javascript/week1/exercise-2.js new file mode 100644 index 000000000..febb682c8 --- /dev/null +++ b/courses/backend/advanced-javascript/week1/exercise-2.js @@ -0,0 +1,3 @@ +import { teas } from "./data/teas.js"; + +teas.forEach(tea => console.log(`${tea.name} (${tea.origin})`)); \ No newline at end of file diff --git a/courses/backend/advanced-javascript/week1/exercise-3.js b/courses/backend/advanced-javascript/week1/exercise-3.js new file mode 100644 index 000000000..f5c604ba6 --- /dev/null +++ b/courses/backend/advanced-javascript/week1/exercise-3.js @@ -0,0 +1,7 @@ +import { teas } from "./data/teas.js"; + +let organicCount = 0; + +teas.forEach(tea => {if (tea.organic) organicCount++}); + +console.log(organicCount); \ No newline at end of file diff --git a/courses/backend/advanced-javascript/week1/exercise-4.js b/courses/backend/advanced-javascript/week1/exercise-4.js new file mode 100644 index 000000000..db1152344 --- /dev/null +++ b/courses/backend/advanced-javascript/week1/exercise-4.js @@ -0,0 +1,3 @@ +import { teas } from "./data/teas.js"; + +const teaNames = teas.map(tea => tea.name); \ No newline at end of file diff --git a/courses/backend/advanced-javascript/week1/exercise-5.js b/courses/backend/advanced-javascript/week1/exercise-5.js new file mode 100644 index 000000000..1f0fa215e --- /dev/null +++ b/courses/backend/advanced-javascript/week1/exercise-5.js @@ -0,0 +1,5 @@ +import { teas } from "./data/teas.js"; + +const teaPrices = teas.map(tea => tea.pricePerGram * 100); + +console.log(teaPrices); \ No newline at end of file diff --git a/courses/backend/advanced-javascript/week1/exercise-6.js b/courses/backend/advanced-javascript/week1/exercise-6.js new file mode 100644 index 000000000..77b04a73b --- /dev/null +++ b/courses/backend/advanced-javascript/week1/exercise-6.js @@ -0,0 +1,5 @@ +import { teas } from "./data/teas.js"; + +const displayStrings = teas.map(tea => `${tea.name} - ${tea.pricePerGram * 100} DKK/100g`); + +console.log(displayStrings); \ No newline at end of file diff --git a/courses/backend/advanced-javascript/week1/exercise-7.js b/courses/backend/advanced-javascript/week1/exercise-7.js new file mode 100644 index 000000000..5ef5dc121 --- /dev/null +++ b/courses/backend/advanced-javascript/week1/exercise-7.js @@ -0,0 +1,3 @@ +import { teas } from "./data/teas.js"; + +const organicTeas = teas.filter(tea => tea.organic); \ No newline at end of file diff --git a/courses/backend/advanced-javascript/week1/exercise-8.js b/courses/backend/advanced-javascript/week1/exercise-8.js new file mode 100644 index 000000000..8b2b88202 --- /dev/null +++ b/courses/backend/advanced-javascript/week1/exercise-8.js @@ -0,0 +1,3 @@ +import { teas } from "./data/teas.js"; + +const japaneseTeas = teas.filter(tea => tea.origin === "Japan"); \ No newline at end of file diff --git a/courses/backend/advanced-javascript/week1/exercise-9.js b/courses/backend/advanced-javascript/week1/exercise-9.js new file mode 100644 index 000000000..21ef3b736 --- /dev/null +++ b/courses/backend/advanced-javascript/week1/exercise-9.js @@ -0,0 +1,3 @@ +import { teas } from "./data/teas.js"; + +const highCaffeineTeas = teas.filter(tea => tea.caffeineLevel === "high"); \ No newline at end of file diff --git a/courses/backend/advanced-javascript/week1/homework/exercise1.js b/courses/backend/advanced-javascript/week1/homework/exercise1.js new file mode 100644 index 000000000..7026fff4e --- /dev/null +++ b/courses/backend/advanced-javascript/week1/homework/exercise1.js @@ -0,0 +1,7 @@ +import { teas } from "../data/teas.js"; + +const result = teas + .filter(tea => tea.caffeineLevel !== 'none') + .map(tea => tea.name.toUpperCase()); + +console.log(result); \ No newline at end of file diff --git a/courses/backend/advanced-javascript/week1/homework/exercise2.js b/courses/backend/advanced-javascript/week1/homework/exercise2.js new file mode 100644 index 000000000..9af58797b --- /dev/null +++ b/courses/backend/advanced-javascript/week1/homework/exercise2.js @@ -0,0 +1,19 @@ +import { teas } from "../data/teas.js"; + +function inventoryReport(teas) { + const totalTeas = teas.length; + const inStock = teas.filter(tea => tea.inStock).length; + const outOfStock = totalTeas - inStock; + const totalInventoryValue = teas.map(tea => tea.pricePerGram * tea.stockCount).reduce((x, y) => x + y, 0); + const totalPricePerGram = teas.map(tea => tea.pricePerGram).reduce((x, y) => x + y, 0); + const averagePricePerGram = Number((totalPricePerGram / totalTeas).toFixed(2)); + return { + totalTeas, + inStock, + outOfStock, + totalInventoryValue, + averagePricePerGram + } + }; + +console.log(inventoryReport(teas)); \ No newline at end of file diff --git a/courses/backend/advanced-javascript/week1/homework/exercise3.js b/courses/backend/advanced-javascript/week1/homework/exercise3.js new file mode 100644 index 000000000..9eebb02cd --- /dev/null +++ b/courses/backend/advanced-javascript/week1/homework/exercise3.js @@ -0,0 +1,12 @@ +import { teas } from "../data/teas.js"; + +function lowStockAlert(teas) { + return teas.filter(tea => tea.stockCount < 50).map(tea => { + return { + name: tea.name, + stock: tea.stockCount + } + }).sort((a, b) => a.stock - b.stock); +} + +console.log(lowStockAlert(teas)); \ No newline at end of file diff --git a/courses/backend/advanced-javascript/week1/homework/exercise4.js b/courses/backend/advanced-javascript/week1/homework/exercise4.js new file mode 100644 index 000000000..ecdb0515e --- /dev/null +++ b/courses/backend/advanced-javascript/week1/homework/exercise4.js @@ -0,0 +1,16 @@ +import { teas } from "../data/teas.js"; + +function teasByOrigin(teas) { + let origins = {}; + teas.forEach(tea => { + const origin = tea.origin; + if (!origins[origin]) { + origins[origin] = [tea.name]; + } else { + origins[origin].push(tea.name); + } + }); + return origins; +} + +console.log(teasByOrigin(teas)); \ No newline at end of file diff --git a/courses/backend/advanced-javascript/week1/homework/exercise5.js b/courses/backend/advanced-javascript/week1/homework/exercise5.js new file mode 100644 index 000000000..78fa70bc8 --- /dev/null +++ b/courses/backend/advanced-javascript/week1/homework/exercise5.js @@ -0,0 +1,19 @@ +import { teas } from "../data/teas.js"; + +function searchTeas(teas, query) { + const queryLower = query.toLowerCase(); + // Return teas where the name contains the query (case-insensitive) + const filtered = teas.filter(tea => tea.name.toLowerCase().includes(queryLower)); + // Return just the names, sorted alphabetically + const names = filtered.map(tea => tea.name).sort(); + return names; +} + +console.log(searchTeas(teas, "earl")); +// Returns: [ 'Earl Grey', 'Jasmine Pearl' ] + +console.log(searchTeas(teas, "dragon")); +// Returns: ["Dragon Well"] + +console.log(searchTeas(teas, "ch")); +// Returns: ["Sencha", "Chamomile", "Matcha", "Lapsang Souchong", "Genmaicha"] diff --git a/courses/backend/advanced-javascript/week1/homework/exercise6.js b/courses/backend/advanced-javascript/week1/homework/exercise6.js new file mode 100644 index 000000000..fe05a62c8 --- /dev/null +++ b/courses/backend/advanced-javascript/week1/homework/exercise6.js @@ -0,0 +1,5 @@ +import { teas } from "../data/teas.js"; + +const totalValue = teas.reduce((sum, tea) => sum + tea.pricePerGram * tea.stockCount, 0); + +console.log("Total inventory value:", totalValue); \ No newline at end of file diff --git a/courses/backend/advanced-javascript/week1/homework/exercise7.js b/courses/backend/advanced-javascript/week1/homework/exercise7.js new file mode 100644 index 000000000..118e53168 --- /dev/null +++ b/courses/backend/advanced-javascript/week1/homework/exercise7.js @@ -0,0 +1,9 @@ +import { teas } from "../data/teas.js"; + +const countByType = teas.reduce((counts, tea) => { + counts[tea.type] ? counts[tea.type]++ : counts[tea.type] = 1; + return counts; +}, {}); + +console.log(countByType); +// Expected: { green: 6, black: 6, herbal: 4, oolong: 2, white: 2 } \ No newline at end of file diff --git a/courses/backend/advanced-javascript/week1/in-class/exercise1.js b/courses/backend/advanced-javascript/week1/in-class/exercise1.js new file mode 100644 index 000000000..dd188b8b7 --- /dev/null +++ b/courses/backend/advanced-javascript/week1/in-class/exercise1.js @@ -0,0 +1,3 @@ +import { teas } from "../data/teas.js"; + +teas.forEach(tea => console.log(tea.name)); \ No newline at end of file diff --git a/courses/backend/advanced-javascript/week1/in-class/exercise10.js b/courses/backend/advanced-javascript/week1/in-class/exercise10.js new file mode 100644 index 000000000..938f6e254 --- /dev/null +++ b/courses/backend/advanced-javascript/week1/in-class/exercise10.js @@ -0,0 +1,5 @@ +import { teas } from "../data/teas.js"; + +const organicTeasInStock = teas.filter(tea => tea.inStock).filter(tea => tea.organic); + +console.log(organicTeasInStock); \ No newline at end of file diff --git a/courses/backend/advanced-javascript/week1/in-class/exercise11.js b/courses/backend/advanced-javascript/week1/in-class/exercise11.js new file mode 100644 index 000000000..234bbd786 --- /dev/null +++ b/courses/backend/advanced-javascript/week1/in-class/exercise11.js @@ -0,0 +1,5 @@ +import { teas } from "../data/teas.js"; + +const greenTeaNames = teas.filter(tea => tea.type === "green").map(tea => tea.name); + +console.log(greenTeaNames); \ No newline at end of file diff --git a/courses/backend/advanced-javascript/week1/in-class/exercise12.js b/courses/backend/advanced-javascript/week1/in-class/exercise12.js new file mode 100644 index 000000000..bbda13d30 --- /dev/null +++ b/courses/backend/advanced-javascript/week1/in-class/exercise12.js @@ -0,0 +1,5 @@ +import { teas } from "../data/teas.js"; + +const organicTeaStrings = teas.filter(tea => tea.organic).map(tea => `${tea.name} - ${tea.pricePerGram * 100} DKK/100g`); + +console.log(organicTeaStrings); \ No newline at end of file diff --git a/courses/backend/advanced-javascript/week1/in-class/exercise13.js b/courses/backend/advanced-javascript/week1/in-class/exercise13.js new file mode 100644 index 000000000..9038af676 --- /dev/null +++ b/courses/backend/advanced-javascript/week1/in-class/exercise13.js @@ -0,0 +1,5 @@ +import { teas } from "../data/teas.js"; + +const japaneseTeasByPrice = teas.filter(tea => tea.origin === "Japan").sort((a, b) => a.pricePerGram - b.pricePerGram); + +console.log(japaneseTeasByPrice); \ No newline at end of file diff --git a/courses/backend/advanced-javascript/week1/in-class/exercise17.js b/courses/backend/advanced-javascript/week1/in-class/exercise17.js new file mode 100644 index 000000000..adb2ef4c4 --- /dev/null +++ b/courses/backend/advanced-javascript/week1/in-class/exercise17.js @@ -0,0 +1,23 @@ +import { teas } from "../data/teas.js"; + +function filterTeas (teas, obj) { + const entries = Object.entries(obj); + entries.forEach((entry) => { + const key = entry[0]; + const value = entry[1]; + teas = teas.filter(tea => tea[key] === value); + }) + return teas; +} + +console.log('Organic teas: ', filterTeas(teas, { organic: true })) +// Returns all organic teas + +console.log('Japanese teas: ', filterTeas(teas, { origin: "Japan" })) +// Returns all Japanese teas + +console.log('Organic Japanese teas: ', filterTeas(teas, { organic: true, origin: "Japan" })) +// Returns organic Japanese teas + +console.log('Green teas in stock: ', filterTeas(teas, { type: "green", inStock: true })) +// Returns green teas that are in stock); \ No newline at end of file diff --git a/courses/backend/advanced-javascript/week1/in-class/exercise2.js b/courses/backend/advanced-javascript/week1/in-class/exercise2.js new file mode 100644 index 000000000..0d41697bc --- /dev/null +++ b/courses/backend/advanced-javascript/week1/in-class/exercise2.js @@ -0,0 +1,3 @@ +import { teas } from "../data/teas.js"; + +teas.forEach(tea => console.log(`${tea.name} (${tea.origin})`)); \ No newline at end of file diff --git a/courses/backend/advanced-javascript/week1/in-class/exercise3.js b/courses/backend/advanced-javascript/week1/in-class/exercise3.js new file mode 100644 index 000000000..8b3f8ca2b --- /dev/null +++ b/courses/backend/advanced-javascript/week1/in-class/exercise3.js @@ -0,0 +1,7 @@ +import { teas } from "../data/teas.js"; + +let organicCount = 0; + +teas.forEach(tea => {if (tea.organic) organicCount++}); + +console.log(organicCount); \ No newline at end of file diff --git a/courses/backend/advanced-javascript/week1/in-class/exercise4.js b/courses/backend/advanced-javascript/week1/in-class/exercise4.js new file mode 100644 index 000000000..664dc0363 --- /dev/null +++ b/courses/backend/advanced-javascript/week1/in-class/exercise4.js @@ -0,0 +1,5 @@ +import { teas } from "../data/teas.js"; + +const teaNames = teas.map(tea => tea.name); + +console.log(teaNames); \ No newline at end of file diff --git a/courses/backend/advanced-javascript/week1/in-class/exercise5.js b/courses/backend/advanced-javascript/week1/in-class/exercise5.js new file mode 100644 index 000000000..85579d2b5 --- /dev/null +++ b/courses/backend/advanced-javascript/week1/in-class/exercise5.js @@ -0,0 +1,5 @@ +import { teas } from "../data/teas.js"; + +const teaPrices = teas.map(tea => tea.pricePerGram * 100); + +console.log(teaPrices); \ No newline at end of file diff --git a/courses/backend/advanced-javascript/week1/in-class/exercise6.js b/courses/backend/advanced-javascript/week1/in-class/exercise6.js new file mode 100644 index 000000000..07f561008 --- /dev/null +++ b/courses/backend/advanced-javascript/week1/in-class/exercise6.js @@ -0,0 +1,5 @@ +import { teas } from "../data/teas.js"; + +const displayStrings = teas.map(tea => `${tea.name} - ${tea.pricePerGram * 100} DKK/100g`); + +console.log(displayStrings); \ No newline at end of file diff --git a/courses/backend/advanced-javascript/week1/in-class/exercise7.js b/courses/backend/advanced-javascript/week1/in-class/exercise7.js new file mode 100644 index 000000000..163d66fc7 --- /dev/null +++ b/courses/backend/advanced-javascript/week1/in-class/exercise7.js @@ -0,0 +1,5 @@ +import { teas } from "../data/teas.js"; + +const organicTeas = teas.filter(tea => tea.organic); + +console.log(organicTeas); \ No newline at end of file diff --git a/courses/backend/advanced-javascript/week1/in-class/exercise8.js b/courses/backend/advanced-javascript/week1/in-class/exercise8.js new file mode 100644 index 000000000..e290ebec9 --- /dev/null +++ b/courses/backend/advanced-javascript/week1/in-class/exercise8.js @@ -0,0 +1,5 @@ +import { teas } from "../data/teas.js"; + +const japaneseTeas = teas.filter(tea => tea.origin === "Japan"); + +console.log(japaneseTeas); \ No newline at end of file diff --git a/courses/backend/advanced-javascript/week1/in-class/exercise9.js b/courses/backend/advanced-javascript/week1/in-class/exercise9.js new file mode 100644 index 000000000..9937e9790 --- /dev/null +++ b/courses/backend/advanced-javascript/week1/in-class/exercise9.js @@ -0,0 +1,5 @@ +import { teas } from "../data/teas.js"; + +const highCaffeineTeas = teas.filter(tea => tea.caffeineLevel === "high"); + +console.log(highCaffeineTeas); \ No newline at end of file diff --git a/courses/backend/databases/database/tasks.sql b/courses/backend/databases/database/tasks.sql new file mode 100644 index 000000000..54af838b9 --- /dev/null +++ b/courses/backend/databases/database/tasks.sql @@ -0,0 +1,292 @@ +CREATE TABLE user ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + name TEXT NOT NULL, + email TEXT UNIQUE, + phone TEXT UNIQUE +); + +CREATE TABLE task ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + title TEXT NOT NULL, + description TEXT, + due_date DATETIME, + created DATETIME NOT NULL, + updated DATETIME NOT NULL, + status_id INTEGER NOT NULL DEFAULT 1, + FOREIGN KEY (status_id) REFERENCES status(id) +); + +CREATE TABLE status ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + name TEXT NOT NULL UNIQUE +); + +CREATE TABLE user_task ( + user_id INTEGER NOT NULL, + task_id INTEGER NOT NULL, + PRIMARY KEY (user_id, task_id), + FOREIGN KEY (user_id) REFERENCES user(id) ON DELETE CASCADE ON UPDATE CASCADE, + FOREIGN KEY (task_id) REFERENCES task(id) ON DELETE CASCADE ON UPDATE CASCADE +); + +INSERT INTO status (name) VALUES ('not started'); +INSERT INTO status (name) VALUES ('in progress'); +INSERT INTO status (name) VALUES ('finished'); + +INSERT INTO user (name, email, phone) VALUES + ('John Doe', '', '+4512345678'), + ('Jane Smith', 'jane@gmail.com', '+4512345679'); + +INSERT INTO task (title, description, created, updated, due_date, status_id) VALUES + ('Study SQL Queries', 'Practice writing SQL queries for data retrieval', datetime('now'), datetime('now'), '2025-08-02', 3), + ('Learn Database Design', 'Study ER modeling and normalization', datetime('now'), datetime('now'), '2025-08-10', 1), + ('Write Unit Tests', 'Add test coverage for user authentication', datetime('now'), datetime('now'), '2025-08-05', 1), + ('Deploy Application', 'Set up production environment', datetime('now'), datetime('now'), '2025-08-20', 1); + + + +-- Users +INSERT INTO user (name, email, phone) VALUES ('Aarika Ellingworth', 'aellingworth0@harvard.edu', '483-396-8795'); +INSERT INTO user (name, email, phone) VALUES ('Pren Goldsworthy', 'pgoldsworthy1@spotify.com', '635-572-8467'); +INSERT INTO user (name, email, phone) VALUES ('Pablo Kisbee', 'pkisbee2@lulu.com', '790-962-8683'); +INSERT INTO user (name, email, phone) VALUES ('Rodie Duncan', 'rduncan3@quantcast.com', '646-743-6191'); +INSERT INTO user (name, email, phone) VALUES ('Aubry Polak', 'apolak4@indiatimes.com', '302-678-7931'); +INSERT INTO user (name, email, phone) VALUES ('Maryrose Meadows', 'mmeadows5@comcast.net', '251-524-6594'); +INSERT INTO user (name, email, phone) VALUES ('Pavel Brushneen', 'pbrushneen6@techcrunch.com', '316-170-3640'); +INSERT INTO user (name, email, phone) VALUES ('Hedy Gerault', 'hgerault7@nymag.com', '176-177-5579'); +INSERT INTO user (name, email, phone) VALUES ('王秀英', 'wang.xiuying@weebly.com', '891-952-6749'); +INSERT INTO user (name, email, phone) VALUES ('إلياس', 'elias@github.com', '202-517-6983'); +INSERT INTO user (name, email, phone) VALUES ('Donald Duck', 'donald@duck.com', NULL); + + +-- Tasks +INSERT INTO task (title, description, created, updated, due_date, status_id) VALUES ('Wash clothes', 'Title says it all.', '2017-10-25 06:54:16', '2017-10-15 13:05:09', null, 2); +INSERT INTO task (title, description, created, updated, due_date, status_id) VALUES ('Become a billionaire', 'This should not take long, just invent a time machine, travel back to 2010 and buy bitcoin', '2017-09-26 03:06:46', '2017-10-08 06:14:31', '2017-12-22 20:58:03', 3); +INSERT INTO task (title, description, created, updated, due_date, status_id) VALUES ('Plan meeting with London office', 'We will probably use skype', '2017-10-04 18:07:37', '2017-10-14 16:01:31', '2017-12-05 19:42:15', 2); +INSERT INTO task (title, description, created, updated, due_date, status_id) VALUES ('Order groceries online', 'The fridge is almost empty, we need eggs and milk', '2017-09-20 19:34:43', '2017-10-15 23:35:45', '2017-12-24 16:00:46', 1); +INSERT INTO task (title, description, created, updated, due_date, status_id) VALUES ('Empty the mailbox', NULL, '2017-09-27 15:17:08', '2017-10-08 17:31:16', null, 2); +INSERT INTO task (title, description, created, updated, due_date, status_id) VALUES ('Fix the flat tire on the bike', 'Tools are in the garage', '2017-09-13 23:16:30', '2017-10-06 04:03:52', '2017-12-07 11:51:11', 2); +INSERT INTO task (title, description, created, updated, due_date, status_id) VALUES ('Wash the car', NULL, '2017-10-06 19:39:16', '2017-10-03 04:49:05', '2017-12-04 17:43:16', 2); +INSERT INTO task (title, description, created, updated, due_date, status_id) VALUES ('Walk the dog', NULL, '2017-09-03 02:47:17', '2017-10-12 18:40:08', null, 3); +INSERT INTO task (title, description, created, updated, due_date, status_id) VALUES ('Write a book', 'Maybe something about dragons?', '2017-10-11 06:14:01', '2017-10-17 12:19:08', '2017-12-21 20:18:05', 2); +INSERT INTO task (title, description, created, updated, due_date, status_id) VALUES ('Do HackYourFuture assignment', NULL, '2017-10-04 13:55:16', '2017-10-10 00:18:05', '2017-12-19 17:01:10', 1); +INSERT INTO task (title, description, created, updated, due_date, status_id) VALUES ('Iron shirts', NULL, '2017-09-23 03:59:58', '2017-10-19 08:30:48', '2017-12-08 11:00:35', 3); +INSERT INTO task (title, description, created, updated, due_date, status_id) VALUES ('Water the potted plants', 'Maybe they need fertilizer as well', '2017-09-29 23:38:42', '2017-10-08 04:24:53', null, 2); +INSERT INTO task (title, description, created, updated, due_date, status_id) VALUES ('Buy wine for the birthday party', 'Both red and white wine', '2017-10-10 14:57:22', '2017-10-14 14:03:30', '2017-12-10 23:43:56', 2); +INSERT INTO task (title, description, created, updated, due_date, status_id) VALUES ('Buy gift for Paul', 'He could use a shirt or a tie and some socks', '2017-09-09 05:22:08', '2017-10-17 15:58:05', '2017-12-04 20:45:18', 3); +INSERT INTO task (title, description, created, updated, due_date, status_id) VALUES ('Change lightbulb in hallway', 'Should be an LED bulb', '2017-10-01 19:07:35', '2017-10-03 10:02:27', '2017-12-08 17:09:03', 3); +INSERT INTO task (title, description, created, updated, due_date, status_id) VALUES ('Wash windows', NULL, '2017-10-02 22:15:17', '2017-10-07 22:31:35', '2017-12-06 03:36:09', 2); +INSERT INTO task (title, description, created, updated, due_date, status_id) VALUES ('Setup salary databases for accounting', 'Use MySQL', '2017-10-25 05:35:33', '2017-10-10 23:22:33', '2017-12-05 00:19:08', 1); +INSERT INTO task (title, description, created, updated, due_date, status_id) VALUES ('Learn how databases work', NULL, '2017-09-06 03:16:47', '2017-10-10 16:56:58', '2017-12-18 05:08:05', 3); +INSERT INTO task (title, description, created, updated, due_date, status_id) VALUES ('Make the databases perform better', 'It should be possible to optimize the indexes', '2017-10-03 09:27:20', '2017-10-01 16:27:46', '2017-12-01 13:28:35', 2); +INSERT INTO task (title, description, created, updated, due_date, status_id) VALUES ('Buy beer for the company party', '2 or 3 cases should be enough', '2017-10-08 01:39:02', '2017-10-13 23:07:41', null, 3); +INSERT INTO task (title, description, created, updated, due_date, status_id) VALUES ('Knit sweater', NULL, '2017-09-22 17:14:55', '2017-10-08 09:01:35', '2017-12-15 20:33:57', 2); +INSERT INTO task (title, description, created, updated, due_date, status_id) VALUES ('Charge electric bicycle', 'It sucks to ride it without a battery!', '2017-10-10 12:25:07', '2017-10-07 21:45:01', '2017-12-10 19:02:17', 1); +INSERT INTO task (title, description, created, updated, due_date, status_id) VALUES ('Buy new phone', 'The battery in the current one only lasts 5 hours 😞', '2017-09-17 00:25:34', '2017-10-09 11:48:12', null, 3); +INSERT INTO task (title, description, created, updated, due_date, status_id) VALUES ('Ride bike around Sjælland', 'Remember rainclothes and tire repair kit!', '2017-10-20 19:21:13', '2017-10-07 01:38:06', '2017-12-19 15:08:18', 2); +INSERT INTO task (title, description, created, updated, due_date, status_id) VALUES ('Look at apartments in Ørestad', '2 or 3 rooms', '2017-10-30 09:47:00', '2017-10-19 06:11:26', null, 1); +INSERT INTO task (title, description, created, updated, due_date, status_id) VALUES ('Empty Mr Fluffy''s litterbox', NULL, '2017-09-28 03:09:06', '2017-10-13 10:38:34', '2017-12-20 23:37:18', 2); +INSERT INTO task (title, description, created, updated, due_date, status_id) VALUES ('Buy new dining room table and chairs', 'Ikea has some on sale', '2017-09-21 12:02:34', '2017-10-02 02:05:11', '2017-12-06 00:14:30', 1); +INSERT INTO task (title, description, created, updated, due_date, status_id) VALUES ('Renew buscard', '3 zones', '2017-10-07 22:47:51', '2017-10-09 15:50:03', '2017-12-01 14:25:40', 2); +INSERT INTO task (title, description, created, updated, due_date, status_id) VALUES ('Sign up for linkedin', 'Make the CV awesome! 😄', '2017-09-04 00:57:47', '2017-10-18 18:07:48', '2017-12-07 23:04:38', 3); +INSERT INTO task (title, description, created, updated, due_date, status_id) VALUES ('Remove facebook from phone', 'To avoid interruptions when working', '2017-10-26 17:15:07', '2017-10-13 03:36:47', '2017-12-19 11:10:02', 3); +INSERT INTO task (title, description, created, updated, due_date, status_id) VALUES ('Backup databases to external disk', 'Remember to store the disk in another physical location', '2017-09-09 17:32:33', '2017-10-01 21:18:59', '2017-12-23 14:21:01', 1); +INSERT INTO task (title, description, created, updated, due_date, status_id) VALUES ('Put up the new lamp in the hallway', NULL, '2017-10-15 05:45:54', '2017-10-16 14:05:35', '2017-12-29 02:29:26', 3); +INSERT INTO task (title, description, created, updated, due_date, status_id) VALUES ('Hang up paintings in living room', NULL, '2017-09-10 05:36:11', '2017-10-09 17:40:42', null, 3); +INSERT INTO task (title, description, created, updated, due_date, status_id) VALUES ('Buy plane ticket to Auckland', 'Check prices online first!', '2017-09-05 09:07:22', '2017-10-15 09:36:06', '2017-12-07 11:10:05', 1); +INSERT INTO task (title, description, created, updated, due_date, status_id) VALUES ('Learn about NoSQL databases', 'MongoDB, CouchDB, etc.', '2017-10-20 01:41:53', '2017-10-04 07:19:56', '2017-12-23 10:13:42', 2); + +-- Users-tasks +INSERT INTO user_task (user_id, task_id) VALUES(1, 5); +INSERT INTO user_task (user_id, task_id) VALUES(1, 35); +INSERT INTO user_task (user_id, task_id) VALUES(1, 11); +INSERT INTO user_task (user_id, task_id) VALUES(2, 4); +INSERT INTO user_task (user_id, task_id) VALUES(2, 26); +INSERT INTO user_task (user_id, task_id) VALUES(2, 29); +INSERT INTO user_task (user_id, task_id) VALUES(3, 22); +INSERT INTO user_task (user_id, task_id) VALUES(3, 13); +INSERT INTO user_task (user_id, task_id) VALUES(3, 19); +INSERT INTO user_task (user_id, task_id) VALUES(4, 24); +INSERT INTO user_task (user_id, task_id) VALUES(4, 20); +INSERT INTO user_task (user_id, task_id) VALUES(5, 20); +INSERT INTO user_task (user_id, task_id) VALUES(5, 18); +INSERT INTO user_task (user_id, task_id) VALUES(5, 15); +INSERT INTO user_task (user_id, task_id) VALUES(6, 10); +INSERT INTO user_task (user_id, task_id) VALUES(6, 7); +INSERT INTO user_task (user_id, task_id) VALUES(6, 27); +INSERT INTO user_task (user_id, task_id) VALUES(7, 33); +INSERT INTO user_task (user_id, task_id) VALUES(7, 18); +INSERT INTO user_task (user_id, task_id) VALUES(7, 23); +INSERT INTO user_task (user_id, task_id) VALUES(8, 26); +INSERT INTO user_task (user_id, task_id) VALUES(8, 30); +INSERT INTO user_task (user_id, task_id) VALUES(8, 11); +INSERT INTO user_task (user_id, task_id) VALUES(9, 34); +INSERT INTO user_task (user_id, task_id) VALUES(9, 15); +INSERT INTO user_task (user_id, task_id) VALUES(9, 1); +INSERT INTO user_task (user_id, task_id) VALUES(10, 29); +INSERT INTO user_task (user_id, task_id) VALUES(10, 16); +INSERT INTO user_task (user_id, task_id) VALUES(10, 1); +INSERT INTO user_task (user_id, task_id) VALUES(11, 26); +INSERT INTO user_task (user_id, task_id) VALUES(11, 27); +INSERT INTO user_task (user_id, task_id) VALUES(11, 17); +INSERT INTO user_task (user_id, task_id) VALUES(11, 2); +INSERT INTO user_task (user_id, task_id) VALUES(1, 3); +INSERT INTO user_task (user_id, task_id) VALUES(2, 6); +INSERT INTO user_task (user_id, task_id) VALUES(3, 8); +INSERT INTO user_task (user_id, task_id) VALUES(4, 9); +INSERT INTO user_task (user_id, task_id) VALUES(5, 12); +INSERT INTO user_task (user_id, task_id) VALUES(6, 14); +INSERT INTO user_task (user_id, task_id) VALUES(7, 21); +INSERT INTO user_task (user_id, task_id) VALUES(8, 25); +INSERT INTO user_task (user_id, task_id) VALUES(9, 28); +INSERT INTO user_task (user_id, task_id) VALUES(10, 31); +INSERT INTO user_task (user_id, task_id) VALUES(11, 32); + +-- Assignment, Part 1: Basic CRUD Operations + +-- Part 1, Question 1: Insert a new user with your own name and email +INSERT INTO user (name, email, phone) + VALUES ('Jessica BK', 'jkavanagh00@gmail.com', NULL); + +-- Part 1, Question 2: Insert a new task assigned to yourself +INSERT INTO task (title, description, created, updated, due_date, status_id) + VALUES ('Learn SQL', 'Practice database queries', '2017-10-25 05:35:33', '2017-10-10 23:22:33', '2026-04-13 00:19:08', 2); +INSERT INTO user_task (user_id, task_id) + VALUES(12, 40); + +-- Part 1, Question 3: Update the title of the task +UPDATE task + SET title = 'Master SQL basics' + WHERE id = 40; + +-- Part 1, Question 4: Change the due date to two weeks from today +UPDATE task + SET due_date = '2026-04-27 00:19:08' + WHERE id = 40; + +-- Part 1, Question 5: Change task status to 'done' +UPDATE task + SET status_id = 3 + WHERE id = 40; + +-- Part 1, Question 6: Delete the task +DELETE FROM task + WHERE id = 40; +DELETE FROM user_task + WHERE task_id = 40; + +-- Assignment, Part 2: Working with Relationships + +-- Part 2, Question 1: List all users who don't have any tasks assigned +SELECT name + FROM user + WHERE id NOT IN (SELECT user_id FROM user_task); + +-- Part 2, Question 2: Find all tasks with a status of 'done' +SELECT * + FROM task + WHERE status_id = 3; + +-- Part 2, Question 3: Find all overdue tasks +SELECT * + FROM task + WHERE due_date < '2026-04-13'; + +-- Assignment, Part 3: Modifying the Database Schema + +-- Part 3, Question 1: Add the priority column to the task table and constrain possible values +ALTER TABLE task + ADD COLUMN priority TEXT NOT NULL DEFAULT 'medium' + CHECK (priority IN ('low', 'medium', 'high')); + +-- Part 3, Question 2: Create a mix of different priority tasks +UPDATE task + SET priority = 'low' + WHERE id > 20; +UPDATE task + SET priority = 'high' + WHERE id % 2 = 0; + +-- Part 3, Question 3: Create a new table called category +CREATE TABLE category ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + name TEXT NOT NULL, + color TEXT NOT NULL +); + +-- Part 3, Question 4: Create a linking table task_category +CREATE TABLE task_category ( + task_id INTEGER NOT NULL, + category_id INTEGER NOT NULL, + PRIMARY KEY (task_id, category_id), + FOREIGN KEY (task_id) REFERENCES task(id) ON DELETE CASCADE ON UPDATE CASCADE, + FOREIGN KEY (category_id) REFERENCES category(id) ON DELETE CASCADE ON UPDATE CASCADE +); + +-- Part 3, Question 5: Insert categories +INSERT INTO category (name, color) VALUES ('work', 'blue'); +INSERT INTO category (name, color) VALUES ('personal', 'green'); +INSERT INTO category (name, color) VALUES ('study', 'red'); +INSERT INTO category (name, color) VALUES ('home', 'orange'); +INSERT INTO category (name, color) VALUES ('hobby', 'purple'); +INSERT INTO category (name, color) VALUES ('fun', 'yellow'); + +-- Part 3, Question 6: Assign categories to tasks +INSERT INTO task_category (task_id, category_id) VALUES (1, 3); +INSERT INTO task_category (task_id, category_id) VALUES (2, 3); +INSERT INTO task_category (task_id, category_id) VALUES (3, 1); +INSERT INTO task_category (task_id, category_id) VALUES (4, 1); +INSERT INTO task_category (task_id, category_id) VALUES (5, 4); +INSERT INTO task_category (task_id, category_id) VALUES (6, 2); +INSERT INTO task_category (task_id, category_id) VALUES (7, 1); + +-- Assignment, Part 4: Advanced Queries + +-- Part 4, Question 1: Find all tasks in a specific category (work, id 1) +SELECT * + FROM task_category tc + JOIN task t + WHERE tc.task_id = t.id + AND tc.category_id = 1; + +-- Part 4, Question 2: List tasks ordered by priority and due date +SELECT * +FROM task +ORDER BY + CASE priority + WHEN 'high' THEN 1 + WHEN 'medium' THEN 2 + WHEN 'low' THEN 3 + ELSE 4 + END, + due_date DESC; + +SELECT * FROM task_category tc; + +-- Part 4, Question 3: Find the category with the most tasks +SELECT + c.name AS category_name, + COUNT(tc.task_id) AS total_tasks +FROM task_category tc +JOIN category c ON c.id = tc.category_id +GROUP BY c.id, c.name +ORDER BY total_tasks DESC +LIMIT 1; + +-- Part 4, Question 4: Get all high priority tasks that are either 'in progress' or 'not started' +-- note: status labels are not consistent with those in exercise +SELECT * + FROM task t + WHERE priority = 'high' + AND (status_id = 1 OR status_id = 2); + +-- Part 4, Question 5: Find users who have tasks in more than one category +SELECT + u.name, + COUNT(DISTINCT tc.category_id) AS category_count +FROM user u +JOIN user_task ut ON u.id = ut.user_id +JOIN task_category tc ON tc.task_id = ut.task_id +GROUP BY u.id, u.name +HAVING COUNT(DISTINCT tc.category_id) > 1 +ORDER BY category_count DESC, u.name; \ No newline at end of file diff --git a/courses/foundation/git/week1/session-playground/apples-file.txt b/courses/foundation/git/week1/session-playground/apples-file.txt new file mode 100644 index 000000000..3534909e6 --- /dev/null +++ b/courses/foundation/git/week1/session-playground/apples-file.txt @@ -0,0 +1 @@ +Apples, apples, so many apples! \ No newline at end of file diff --git a/courses/foundation/git/week1/session-playground/bananas-file.txt b/courses/foundation/git/week1/session-playground/bananas-file.txt new file mode 100644 index 000000000..76f82cb69 --- /dev/null +++ b/courses/foundation/git/week1/session-playground/bananas-file.txt @@ -0,0 +1 @@ +Bananas \ No newline at end of file diff --git a/courses/foundation/git/week1/session-playground/colors.txt b/courses/foundation/git/week1/session-playground/colors.txt new file mode 100644 index 000000000..81fe5ffea --- /dev/null +++ b/courses/foundation/git/week1/session-playground/colors.txt @@ -0,0 +1,4 @@ +Blue +Red +Yellow +Orange \ No newline at end of file diff --git a/courses/foundation/git/week1/session-playground/movies.txt b/courses/foundation/git/week1/session-playground/movies.txt new file mode 100644 index 000000000..907361979 --- /dev/null +++ b/courses/foundation/git/week1/session-playground/movies.txt @@ -0,0 +1,2 @@ +Cinderella +The Little Mermaid \ No newline at end of file diff --git a/courses/foundation/git/week1/session-playground/my-assignment.txt b/courses/foundation/git/week1/session-playground/my-assignment.txt new file mode 100644 index 000000000..94984a082 --- /dev/null +++ b/courses/foundation/git/week1/session-playground/my-assignment.txt @@ -0,0 +1,2 @@ +git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, +git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git,git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git,git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git,git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git,git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git,git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git,git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git,git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git,git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git,git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git,git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git,git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git,git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git,git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git,git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git,git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git,git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git,git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git,git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git,git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git,git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git,git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git,git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git,git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git,git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git,git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, git, \ No newline at end of file diff --git a/courses/foundation/git/week1/session-playground/oranges-file.txt b/courses/foundation/git/week1/session-playground/oranges-file.txt new file mode 100644 index 000000000..73a8088e9 --- /dev/null +++ b/courses/foundation/git/week1/session-playground/oranges-file.txt @@ -0,0 +1 @@ +Oranges \ No newline at end of file diff --git a/courses/foundation/intro-to-frontend/HYFBay/index.html b/courses/foundation/intro-to-frontend/HYFBay/index.html index 07f60fe48..bf6d28c7e 100644 --- a/courses/foundation/intro-to-frontend/HYFBay/index.html +++ b/courses/foundation/intro-to-frontend/HYFBay/index.html @@ -1,14 +1,26 @@ HyfBay - + - + + -
+

HYFBay

+ + + + + + + + + + +
ItemPriceRating
+
+ +
- + \ No newline at end of file diff --git a/courses/foundation/intro-to-frontend/HYFBay/main.css b/courses/foundation/intro-to-frontend/HYFBay/main.css index 9f6b12f10..fd49ca85f 100644 --- a/courses/foundation/intro-to-frontend/HYFBay/main.css +++ b/courses/foundation/intro-to-frontend/HYFBay/main.css @@ -1,6 +1,7 @@ body { font-family: "Open Sans", sans-serif; background-color: #f9fbfd; + justify-content: center; } * { @@ -11,6 +12,7 @@ body, h1, h2 { margin: 0; + text-align: center; } ul { @@ -18,3 +20,47 @@ ul { margin: 0; padding: 0; } + +table { + padding: 40px; + width: 375px; + margin: 0 auto; + table-layout: fixed; + border-collapse: collapse; +} + +th, +td, +tr { + text-align: left; + padding-top: 5px; + padding-bottom: 5px; +} + +th { + background-color: green; + color: white; +} + +tr { + text-align: left; +} + +tr:nth-child(even) { + background-color: #d8d8d8; +} + +th:nth-child(1), td:nth-child(1) { + width: 50%; + padding-left: 5px; +} +th:nth-child(2) { + width: 25%; +} +th:nth-child(3) { + width: 25%; +} + +.stars { + color: rgb(255, 174, 0); +} diff --git a/courses/foundation/intro-to-frontend/HYFBay/main.js b/courses/foundation/intro-to-frontend/HYFBay/main.js index 00111ae11..5c518d5e6 100644 --- a/courses/foundation/intro-to-frontend/HYFBay/main.js +++ b/courses/foundation/intro-to-frontend/HYFBay/main.js @@ -3,9 +3,48 @@ console.log("Script loaded"); const products = getAvailableProducts(); console.log(products); -// This should create the ul and the li's with the individual products details -function renderProducts(products) { - // your code goes here +const renderProducts = products => { + const tbody = document.querySelector("tbody"); + tbody.innerHTML = ""; + + for (let i = 0; i < products.length; i++) { + const row = document.createElement("tr"); + + const name = document.createElement("td"); + name.innerHTML = "" + products[i].name + ""; + row.appendChild(name); + + const price = document.createElement("td"); + price.innerHTML = formatPrice(products[i].price) + " kr."; + row.appendChild(price); + + const rating = document.createElement("td"); + rating.innerHTML = formatRating(products[i].rating); + row.appendChild(rating); + + tbody.appendChild(row); + } +} + +// star: U+2605; half-star: U+2BE8 + +const formatPrice = number => { + return number.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); +} + +const formatRating = number => { + let formattedRating = "" + if (number % 2 === 0) { + for (let i = 0; i < number; i += 2) { + formattedRating += "★ "; + } + } else { + for (let i = 0; i < number-2; i += 2) { + formattedRating += "★ "; + } + formattedRating += "⯨ "; + } + return '' + formattedRating + ''; } -renderProducts(products); +renderProducts(products); diff --git a/courses/foundation/intro-to-frontend/HogwartsHouseGenerator/index.html b/courses/foundation/intro-to-frontend/HogwartsHouseGenerator/index.html new file mode 100644 index 000000000..0950f8c83 --- /dev/null +++ b/courses/foundation/intro-to-frontend/HogwartsHouseGenerator/index.html @@ -0,0 +1,88 @@ + + + + + + + +
+

The Sorting Hat

+ + + + + + + +
+
+ +

+
+ + \ No newline at end of file diff --git a/courses/foundation/intro-to-frontend/assignments/codewars-katas.js b/courses/foundation/intro-to-frontend/assignments/codewars-katas.js new file mode 100644 index 000000000..43e07ff00 --- /dev/null +++ b/courses/foundation/intro-to-frontend/assignments/codewars-katas.js @@ -0,0 +1,29 @@ +// remove first and last character +function removeChar(str){ +if (str.length < 3) { + return ""; +} else { + return str.slice(1, str.length-1); +} +}; + +// counting sheep... +function countSheeps(sheep) { + let count = 0; + for (let i = 0; i < sheep.length; i++) { + if (sheep[i] === true) count++; + } + return count; +} + +// string ends with +const solution = (str, ending) => str.slice(str.length - ending.length) === ending; + +// odd or even? +function oddOrEven(array) { + if (array.length === 0 || array.reduce((x, y) => x + y) % 2 === 0) { + return "even"; + } else { + return "odd"; + } +} \ No newline at end of file diff --git a/courses/foundation/intro-to-frontend/week1/index.html b/courses/foundation/intro-to-frontend/week1/index.html new file mode 100644 index 000000000..1d4a49bc9 --- /dev/null +++ b/courses/foundation/intro-to-frontend/week1/index.html @@ -0,0 +1,94 @@ + + + + + + + + PAYMENT <span>FORM</span> + + + + + + +
+
+

SOME HEADER

+

Some optional stuff.

+
+
+

Order Summary

+
+
TOTAL
+
$333 / month
+
+
+
+
TOTAL
+
$100
+
+
+
+ +
+
+

Payment Method

+
+ + +
+
+ + +
+

Card Info

+
+
+ + + +
+
+
+ + +
+ +
+ + + +
+
+
+
+ + +

Need Help?

+
+ + + + \ No newline at end of file diff --git a/courses/foundation/intro-to-frontend/week1/source.js b/courses/foundation/intro-to-frontend/week1/source.js new file mode 100644 index 000000000..060e62d99 --- /dev/null +++ b/courses/foundation/intro-to-frontend/week1/source.js @@ -0,0 +1,15 @@ +const paymentTypes = document.querySelector('.payment-method-selectors'); +const cardPaymentSelector = paymentTypes.querySelector('#card-payment-selector'); +const paypalPaymentSelector = paymentTypes.querySelector('#paypal-payment-selector'); +const cardPaymentCard = document.querySelector('.card-payment-card'); +const paypalPaymentCard = document.querySelector('.paypal-payment-card'); + +cardPaymentSelector.addEventListener ('click', () => highlight(cardPaymentCard)); +paypalPaymentSelector.addEventListener ('click', () => highlight(paypalPaymentCard)); + +function highlight(target) { + console.log('click') + paypalPaymentCard.classList.remove('selected') + cardPaymentCard.classList.remove('selected') + target.classList.add('selected') +} \ No newline at end of file diff --git a/courses/foundation/intro-to-frontend/week1/styles.css b/courses/foundation/intro-to-frontend/week1/styles.css new file mode 100644 index 000000000..e3a2e8990 --- /dev/null +++ b/courses/foundation/intro-to-frontend/week1/styles.css @@ -0,0 +1,238 @@ +@import url('https://fonts.google.com/specimen/Montserrat'); + +html { + background-color: #2310164D; +} + +body { + align-items: center; + justify-content: center; + margin: auto; + width: 100vw; + min-width: 300px; + min-height: 50px; + font-family: Arial, Helvetica, sans-serif; +} + +header { + min-height: 50px; + margin: 0 auto; + min-width: 300px; + max-width: 800px; +} + +a { + text-decoration: none; +} + +.header-text { + font-family: Montserrat; + text-align: center; + margin: 0 auto; + color: #ffffff; + justify-content: center; + padding: 10px; +} + +.header-text h1 { + font-size: 30px; + margin: 0 auto; +} + +.header-text p { + font-size: 20px; + margin: 0 auto; +} + +.order-summary { + margin: 0 auto; + text-align: center; + background: linear-gradient(90deg, #FD7B46, #FE4E9B); + max-width: 800px; + padding: 15px 0 15px 0; +} + +.order-summary h1 { + font-size: 24px; + color: white; +} + +.order-total-top { + width: 87.7%; + color: white; + display: flex; + justify-content: space-between; + margin: 7px auto; + font-weight: 400; +} + +.horizontal-line { + width: 87.7%; + height: 1px; + background: #fff; + margin: 0 auto; +} + +.order-total-bottom { + width: 87.7%; + color: white; + display: flex; + justify-content: space-between; + margin: 7px auto; + font-weight: 700; +} + +form { + max-width: 800px; + margin: 0 auto; + background-color: #ffffff; +} + +.card-info { + background-color: #ffffff; + width: 87.7%; + max-width: 800px; + margin: 0 auto; +} + +.payment-method { + background-color: #ffffff; + width: 87.7%; + padding-top: 10px; + padding-bottom: 10px; + margin: 0 auto; +} + +h2 { + text-align: center; +} + +input[type='radio'] { + appearance:none; +} + +.payment-method-selectors { + display: flex; + gap: 20px; +} + +.payment-method-selectors label { + display: flex; + flex: 1; +} + +.card { + display: flex; + flex-direction: column; + height: 110px; + min-width: 120px; + max-width: 300px; + flex: 1; + font-family: Montserrat; + font-style: bold; + filter: drop-shadow(8px 8px 20px #0000004D); + background-color: #ffffff; + margin: auto; + border-radius: 10px; + justify-content: center; + align-items: center; + font-size: 12px; + font-weight: 700; +} + +.selected { + border: 4px solid #FE4E9B; + box-sizing: border-box; +} + +.paypal-logo { + width: 22px; + filter: grayscale(100%); + margin-bottom: 10px; +} + +.card-logos { + width: 100px; + margin-bottom: 10px; +} + +.exp-and-cvv { + display: flex; + flex-direction: row; + margin: 0 auto; + justify-content: space-between; +} + +label { + font-family: Montserrat; + font-weight: 600; + font-size: 16px; + color: #939393; + text-align: center; + display: block; + margin-bottom: 6px; +} + +.exp-and-cvv-inputs { + width: 43.3%; + position: relative; +} + +.all-payment-info { + display: flex; + flex-direction: column; + width: 100%; + gap: 20px; +} + +.input-bar { + width: 100%; + height: 24px; + border: 1px solid #939393; + background-color: #F3F1F2; + border-radius: 2px; + font-size: 16px; + text-align: center; + margin: 0 auto 20px auto; + display: block; + box-sizing: border-box; +} + +.card-info-container { + width: 100%; + position: relative +} + +.info-icon { + position: absolute; + width: 20px; + right: 2px; + top: 27.5px; +} + +.buy-now { + width: 260px; + height: 68px; + border-radius: 68px; + display: block; + margin: 0 auto; + margin-top: 20px; + background: linear-gradient(90deg, #FD7B46, #FE4E9B); + font-family: Montserrat; + font-weight: 700; + font-size: 24px; + border: 0; + color: #ffffff; +} + +.help-button { + font-weight: 700; + font-size: 18px; + text-align: center; + background: linear-gradient(90deg, #FD7B46, #FE4E9B); + -webkit-background-clip: text; + -webkit-text-fill-color: transparent; + background-clip: text; + padding-top: 24px; + padding-bottom: 40px; +} \ No newline at end of file diff --git a/courses/foundation/intro-to-javascript/week-1/ageify.js b/courses/foundation/intro-to-javascript/week-1/ageify.js new file mode 100644 index 000000000..f455ad006 --- /dev/null +++ b/courses/foundation/intro-to-javascript/week-1/ageify.js @@ -0,0 +1,5 @@ +const yearOfBirth = 1989; +const yearFuture = 2030; +const age = yearFuture - yearOfBirth; + +console.log("You will be " + age + " years old in " + yearFuture); \ No newline at end of file diff --git a/courses/foundation/intro-to-javascript/week-1/ezNamey.js b/courses/foundation/intro-to-javascript/week-1/ezNamey.js new file mode 100644 index 000000000..2339926e2 --- /dev/null +++ b/courses/foundation/intro-to-javascript/week-1/ezNamey.js @@ -0,0 +1,7 @@ +const firstWords = ["Easy", "Awesome", "Corporate", "Cool", "Fun", "Good", "Great", "Better", "Superb", "Yes"]; +const secondWords = ["Corporation", "Company", "Firm", "Business", "Fund", "Alliance", "Equity", "Capital", "Finance", "Holdings"]; + +const getRandom = (arr) => arr[Math.floor(Math.random() * arr.length)]; +const startupName = getRandom(firstWords) + " " + getRandom(secondWords); + +console.log("Your new app name is " + startupName + "!"); \ No newline at end of file diff --git a/courses/foundation/intro-to-javascript/week-1/goodBoyOldBoy.js b/courses/foundation/intro-to-javascript/week-1/goodBoyOldBoy.js new file mode 100644 index 000000000..db752f52c --- /dev/null +++ b/courses/foundation/intro-to-javascript/week-1/goodBoyOldBoy.js @@ -0,0 +1,15 @@ + +const dogYearOfBirth = 2023; +const dogYearFuture = 2033; +const humanYears = dogYearFuture - dogYearOfBirth +const dogYears = humanYears*7; + +let shouldShowResultInDogYears = true; +shouldShowResultInDogYears ? + console.log(`Your dog will be ${dogYears} dog years old in ${dogYearFuture}`) : + console.log(`Your dog will be ${humanYears} human years old in ${dogYearFuture}`); + +shouldShowResultInDogYears = false; +shouldShowResultInDogYears ? + console.log(`Your dog will be ${dogYears} dog years old in ${dogYearFuture}`) : + console.log(`Your dog will be ${humanYears} human years old in ${dogYearFuture}`); \ No newline at end of file diff --git a/courses/foundation/intro-to-javascript/week-1/houseyPricey.js b/courses/foundation/intro-to-javascript/week-1/houseyPricey.js new file mode 100644 index 000000000..cbc98b061 --- /dev/null +++ b/courses/foundation/intro-to-javascript/week-1/houseyPricey.js @@ -0,0 +1,27 @@ +function ripOffDetector(clientName) { + const volumeInMeters = customerData[clientName].width * customerData[clientName].depth * customerData[clientName].height; + const housePrice = (volumeInMeters * 2.5 * 1000) + (customerData[clientName].gardenSizeInM2 * 300); + customerData[clientName].quotedPrice <= housePrice ? + console.log(`Looking good, ${clientName}, you should buy!`) : + console.log(`What a rip off! Get out of there ${clientName}!`); +} + +const customerData = { + Peter: { + quotedPrice: 2500000, + gardenSizeInM2: 100, + width: 8, + depth: 10, + height: 10 + }, + Julia: { + quotedPrice: 1000000, + gardenSizeInM2: 70, + width: 5, + depth: 11, + height: 8 + } +} + +ripOffDetector("Peter"); +ripOffDetector("Julia"); \ No newline at end of file diff --git a/courses/foundation/intro-to-javascript/week-2/candyHelper.js b/courses/foundation/intro-to-javascript/week-2/candyHelper.js new file mode 100644 index 000000000..3f6a38321 --- /dev/null +++ b/courses/foundation/intro-to-javascript/week-2/candyHelper.js @@ -0,0 +1,20 @@ +const pricePerGram = { + sweet: 0.5, + chocolate: 0.7, + toffee: 1.1, + chewingGum: 0.03 +}; + +const boughtCandyPrices = []; +const amountToSpend = Math.random() * 100; + +function addCandy(candyType, grams) { + const totalSpent = boughtCandyPrices.length > 0 ? boughtCandyPrices.reduce((x, y) => x + y) : 0; + const candyPrice = pricePerGram[candyType] * grams; + if (totalSpent + candyPrice < amountToSpend) { + boughtCandyPrices.push(candyPrice); + console.log("You can buy more, so please do!"); + } else { + console.log("Enough candy for you!"); + } +} \ No newline at end of file diff --git a/courses/foundation/intro-to-javascript/week-2/clothingPicker.js b/courses/foundation/intro-to-javascript/week-2/clothingPicker.js new file mode 100644 index 000000000..30085bf9f --- /dev/null +++ b/courses/foundation/intro-to-javascript/week-2/clothingPicker.js @@ -0,0 +1,15 @@ +function clothingPicker(temp) { + if (temp >= 20) { + return "T-Shirt"; + } else if (temp >= 15) { + return "Sweater"; + } else if (temp >= 10) { + return "Coat"; + } else if (temp >= 0) { + return "Puffer jacket"; + } else if (temp < 0) { + return "Slippers and pajamas"; + } else { + return "Invalid temperature entered"; + } +} \ No newline at end of file diff --git a/courses/foundation/intro-to-javascript/week-2/getFullName.js b/courses/foundation/intro-to-javascript/week-2/getFullName.js new file mode 100644 index 000000000..d189877af --- /dev/null +++ b/courses/foundation/intro-to-javascript/week-2/getFullName.js @@ -0,0 +1,12 @@ +const honorifics = { + man: "Lord", + woman: "Lady", + nonBinary: "Regent" +}; + +const fullName1 = getFullName("John", "Doe"); +const fullName2 = getFullName("Jane", "Doe", true); + +function getFullName(firstName, secondName, useFormalName, gender) { + return useFormalName && gender ? `${honorifics[gender]} ${firstName} ${secondName}` : `${firstName} ${secondName}`; +}; \ No newline at end of file diff --git a/courses/foundation/intro-to-javascript/week-2/getWeekday.js b/courses/foundation/intro-to-javascript/week-2/getWeekday.js new file mode 100644 index 000000000..ad9ecf985 --- /dev/null +++ b/courses/foundation/intro-to-javascript/week-2/getWeekday.js @@ -0,0 +1,16 @@ +const weekdays = [ + "Sunday", + "Monday", + "Tuesday", + "Wednesday", + "Thursday", + "Friday", + "Saturday", +]; + +const currentDay = new Date().getDay(); + +function getWeekday(num) { + const targetDay = currentDay + num % 7; + return num === 0 ? "Today" : weekdays[targetDay]; +} \ No newline at end of file diff --git a/courses/foundation/intro-to-javascript/week-2/studentManager.js b/courses/foundation/intro-to-javascript/week-2/studentManager.js new file mode 100644 index 000000000..32476e311 --- /dev/null +++ b/courses/foundation/intro-to-javascript/week-2/studentManager.js @@ -0,0 +1,19 @@ +const class07Students = []; + +function addStudentToClass(studentName) { + if (studentName.length < 1) { + console.log("Invalid name entered"); + } else if (studentName === "The Queen") { + class07Students.push(studentName); + } else if (class07Students.includes(studentName)) { + console.log(`Student ${studentName} is already in the class`); + } else if (getNumberOfStudents() > 6) { + console.log("Cannot add more students to class 07"); + } else { + class07Students.push(studentName); + }; +}; + +function getNumberOfStudents() { + return class07Students.length; +}; \ No newline at end of file diff --git a/courses/foundation/intro-to-javascript/week-3/CactusIO-interactive.js b/courses/foundation/intro-to-javascript/week-3/CactusIO-interactive.js new file mode 100644 index 000000000..3cd001d00 --- /dev/null +++ b/courses/foundation/intro-to-javascript/week-3/CactusIO-interactive.js @@ -0,0 +1,33 @@ +const activities = []; +const limit = 60; + + +function getCurrentDate() { + const current = new Date; + const day = current.getDate(); + const month = current.getMonth(); + const year = current.getFullYear(); + return `${day}/${month}-${year}` +} + +function addActivity(activity, duration) { + activities.push({ + date: getCurrentDate(), + activity: activity, + duration: duration + }); +} + +function showStatus(activities) { + const length = activities.length; + if (length < 1) return "Add some activities before calling showStatus."; + let totalMinutes = 0; + for (let i = 0; i < length; i++) { + totalMinutes += activities[i].duration; + } + if (totalMinutes > limit) return "You have reached your limit, no more smartphoning for you!"; + // NOTE: instructions unclear as to whether or not this function should return or log this result + return activities.length > 1 ? + `You have added ${length} activities. They amount to ${totalMinutes} minutes of usage.` : + `You have added 1 activity. It amounts to ${totalMinutes} minutes of usage.`; +} \ No newline at end of file diff --git a/courses/foundation/intro-to-javascript/week-3/NOnoN0nOYes.js b/courses/foundation/intro-to-javascript/week-3/NOnoN0nOYes.js new file mode 100644 index 000000000..8889e3427 --- /dev/null +++ b/courses/foundation/intro-to-javascript/week-3/NOnoN0nOYes.js @@ -0,0 +1,40 @@ +const notes = []; + +function saveNote(content, id) { + notes.push({ + content: content, + id: id, + }); +} + +function getNote(id) { + for (let i = 0; i < notes.length; i++) { + if (notes[i].id === id) return notes[i] + } + return "Invalid ID entered" +} + +function favouriteNote(id) { + for (let i = 0; i < notes.length; i++) { + if (notes[i].id === id) { + notes[i].favourite = true; + break; + } + } +} + +function logOutNotesFormatted() { + for (let i = 0; i < notes.length; i++) { + const note = notes[i]; + console.log(`The note with id: ${note.id}, has the following note text: ${note.content}`); + } +} + +function logOutFavouritesFormatted() { + for (let i = 0; i < notes.length; i++) { + const note = notes[i]; + if (note.favourite) { + console.log(`The note with id: ${note.id}, has the following note text: ${note.content}`); + } + } +} \ No newline at end of file diff --git a/courses/foundation/intro-to-javascript/week-3/bonus-assignments/jobMatching1.js b/courses/foundation/intro-to-javascript/week-3/bonus-assignments/jobMatching1.js new file mode 100644 index 000000000..2621f46bd --- /dev/null +++ b/courses/foundation/intro-to-javascript/week-3/bonus-assignments/jobMatching1.js @@ -0,0 +1,7 @@ +function match(candidate, job) { + if (!candidate.minSalary || !job.maxSalary) { + throw Error(); + } else { + return candidate.minSalary * 0.9 <= job.maxSalary; + } +} \ No newline at end of file diff --git a/courses/foundation/intro-to-javascript/week-3/bonus-assignments/jobMatching2.js b/courses/foundation/intro-to-javascript/week-3/bonus-assignments/jobMatching2.js new file mode 100644 index 000000000..ddde6afd2 --- /dev/null +++ b/courses/foundation/intro-to-javascript/week-3/bonus-assignments/jobMatching2.js @@ -0,0 +1,28 @@ +function matchEquity(candidate, job) { + if (candidate.desiresEquity && job.equityMax > 0) { + return true + } else if (!candidate.desiresEquity) { + return true + } else { + return false + } +} + +function matchLocation(candidate, job) { + const locations = [...candidate.desiredLocations,candidate.currentLocation]; + for (let i = 0; i < locations.length; i++) { + if (job.locations.includes(locations[i])) return true + } + return false +} + +function match(job, candidates) { + const matches = []; + for (let i = 0; i < candidates.length; i++) { + if (matchEquity(candidates[i], job) + && matchLocation(candidates[i], job)) { + matches.push(candidates[i]); + } + } + return matches +} \ No newline at end of file diff --git a/courses/foundation/intro-to-javascript/week-3/bonus-assignments/kata.js b/courses/foundation/intro-to-javascript/week-3/bonus-assignments/kata.js new file mode 100644 index 000000000..2621f46bd --- /dev/null +++ b/courses/foundation/intro-to-javascript/week-3/bonus-assignments/kata.js @@ -0,0 +1,7 @@ +function match(candidate, job) { + if (!candidate.minSalary || !job.maxSalary) { + throw Error(); + } else { + return candidate.minSalary * 0.9 <= job.maxSalary; + } +} \ No newline at end of file diff --git a/courses/foundation/intro-to-javascript/week-3/bonus-assignments/unfinished-loop.js b/courses/foundation/intro-to-javascript/week-3/bonus-assignments/unfinished-loop.js new file mode 100644 index 000000000..077d1ea76 --- /dev/null +++ b/courses/foundation/intro-to-javascript/week-3/bonus-assignments/unfinished-loop.js @@ -0,0 +1,7 @@ +function createArray(number) { + const newArray = []; + for (let counter = 1; counter <= number; counter++) { + newArray.push(counter); + } + return newArray; +} \ No newline at end of file diff --git a/courses/foundation/intro-to-javascript/week-3/in-class/arrayPractice.js b/courses/foundation/intro-to-javascript/week-3/in-class/arrayPractice.js new file mode 100644 index 000000000..ddd90d8ba --- /dev/null +++ b/courses/foundation/intro-to-javascript/week-3/in-class/arrayPractice.js @@ -0,0 +1,22 @@ +fruits = ["apple", "banana", "pear"] + +const addAtBeginningOfArray = (value, arr) => { + const result = [value]; + for (let i = 0; i < arr.length; i++) { + result.push(arr[i]); + } + return result +} + +const addAtBeginningOfArrayAndModify = (value) => { + for (let i = fruits.length-1; i <= 0; i--) { + fruits[i + 1] = arr[i]; + } + fruits[0] = value; + return fruits +} + + +console.log(addAtBeginningOfArray("lychee", fruits)); +addAtBeginningOfArrayAndModify("cherry"); +console.log(fruits); \ No newline at end of file diff --git a/courses/foundation/intro-to-javascript/week-3/itemArrayRemoval.js b/courses/foundation/intro-to-javascript/week-3/itemArrayRemoval.js new file mode 100644 index 000000000..0d0cc343e --- /dev/null +++ b/courses/foundation/intro-to-javascript/week-3/itemArrayRemoval.js @@ -0,0 +1,20 @@ +const names = [ + "Peter", + "Ahmad", + "Yana", + "kristina", + "Rasmus", + "Samuel", + "Katrine", + "Tala", +]; +const nameToRemove = "Ahmad"; + +function removeName(nameToRemove) { + for (let i = 0; i < names.length; i++) { + if(names[i] === nameToRemove) names.splice(i, 1); + } +} + +removeName(nameToRemove); +console.log(names); // ['Peter', 'Yana', 'kristina', 'Rasmus', 'Samuel', 'Katrine', 'Tala'] \ No newline at end of file diff --git a/courses/foundation/intro-to-javascript/week-3/seriesDuration.js b/courses/foundation/intro-to-javascript/week-3/seriesDuration.js new file mode 100644 index 000000000..76af096f9 --- /dev/null +++ b/courses/foundation/intro-to-javascript/week-3/seriesDuration.js @@ -0,0 +1,44 @@ +const seriesDurations = [ + { + title: "Game of thrones", + days: 3, + hours: 1, + minutes: 0, + }, + { + title: "Sopranos", + days: 3, + hours: 14, + minutes: 0, + }, + { + title: "The Wire", + days: 2, + hours: 12, + minutes: 0, + }, +]; + +function calculatePercentage(obj) { + const totalHoursWatched = obj.hours + (obj.days * 24); + const hoursInAYear = 8760*80; + const percentage = ((totalHoursWatched / hoursInAYear) * 100); + return percentage.toFixed(3); +} + +function calculateTimeSpent(arr) { + const total = { + days: 0, + hours: 0, + minutes: 0 + }; + for (let i = 0; i < arr.length; i++) { + const series = seriesDurations[i]; + console.log(`${series.title} took ${calculatePercentage(series)}% of my life`) + total.days += series.days; + total.hours += series.hours; + } + console.log(`In total, that is ${calculatePercentage(total)}% of my life`); +} + +calculateTimeSpent(seriesDurations); \ No newline at end of file diff --git a/courses/foundation/intro-to-javascript/week-3/travelCalculator.js b/courses/foundation/intro-to-javascript/week-3/travelCalculator.js new file mode 100644 index 000000000..c11677870 --- /dev/null +++ b/courses/foundation/intro-to-javascript/week-3/travelCalculator.js @@ -0,0 +1,17 @@ +const travelInformation = { + speed: 50, + destinationDistance: 432, +}; + +const travelTime = calculateTravelTime(travelInformation); +console.log(travelTime); + +function calculateTravelTime(obj) { + const speed = obj.speed; + const distance = obj.destinationDistance; + const totalSeconds = Math.floor((distance / speed) * 3600); + const hours = Math.floor(totalSeconds / 3600); + const minutes = Math.floor((totalSeconds % 3600) / 60); + const seconds = totalSeconds - hours * 3600 - minutes * 60; + return `${hours} hours, ${minutes} minutes and ${seconds} seconds` +} \ No newline at end of file diff --git a/courses/foundation/intro-to-using-ai/week-1/assignment/ai-index-a.html b/courses/foundation/intro-to-using-ai/week-1/assignment/ai-index-a.html new file mode 100644 index 000000000..692f9cb55 --- /dev/null +++ b/courses/foundation/intro-to-using-ai/week-1/assignment/ai-index-a.html @@ -0,0 +1,145 @@ + + + + + + About Me + + + + +
+

About Me

+

Hello! My name is [Your Name] and I'm excited to share a bit about myself. I'm currently learning web development and exploring the world of programming. This page is a simple introduction to who I am and what interests me.

+ +

My Interests

+ + + +
+ + + + \ No newline at end of file diff --git a/courses/foundation/intro-to-using-ai/week-1/assignment/ai-index-b.html b/courses/foundation/intro-to-using-ai/week-1/assignment/ai-index-b.html new file mode 100644 index 000000000..4faa61c9a --- /dev/null +++ b/courses/foundation/intro-to-using-ai/week-1/assignment/ai-index-b.html @@ -0,0 +1,118 @@ + + + + + + About Me + + + + +

About Me

+

Hello! I'm a passionate learner currently studying web development and programming. I enjoy exploring new technologies and building creative projects that solve real-world problems.

+ +

My Interests

+ + + + + + + + \ No newline at end of file diff --git a/courses/foundation/intro-to-using-ai/week-1/assignment/ai-index.html b/courses/foundation/intro-to-using-ai/week-1/assignment/ai-index.html new file mode 100644 index 000000000..3b2b735a5 --- /dev/null +++ b/courses/foundation/intro-to-using-ai/week-1/assignment/ai-index.html @@ -0,0 +1,122 @@ + + + + + + About Me + + + + + + +

About Me

+

Hello! I'm a passionate learner currently studying web development through the Hack Your Future program. I'm excited about building my skills in programming and creating meaningful digital experiences.

+

My Interests

+ + + + + + \ No newline at end of file diff --git a/courses/foundation/intro-to-using-ai/week-1/assignment/prompts.txt b/courses/foundation/intro-to-using-ai/week-1/assignment/prompts.txt new file mode 100644 index 000000000..ef0663daf --- /dev/null +++ b/courses/foundation/intro-to-using-ai/week-1/assignment/prompts.txt @@ -0,0 +1,16 @@ +I would like to make a simple HTML page that introduces me and my interests. +Begin by creating an HTML document and adding a heading with the text "About Me" at the top. + +Add a short introduction as a paragraph element below the heading. + +Add an unordered list of my interests (juggling, games, programming). + +Centre the heading. + +Change the font to a custom font. + +Add a background colour. + +Add a "fun" button somewhere on the page which changes the background colour to a random colour when clicked. + +Make this page responsive, using media queries to style the page for mobile and desktop size screens. \ No newline at end of file diff --git a/courses/foundation/intro-to-using-ai/week-1/assignment/reflections.txt b/courses/foundation/intro-to-using-ai/week-1/assignment/reflections.txt new file mode 100644 index 000000000..3ad380828 --- /dev/null +++ b/courses/foundation/intro-to-using-ai/week-1/assignment/reflections.txt @@ -0,0 +1,3 @@ +I decided to approach this exercise by writing a set of 8 prompts of varying specificity and then tasking the LLM with building the same page three times to compare the different outputs. +As expected, the basic HTML structure is consistent accross the three documents. Once more complex elements with less specificity (such as the button and the responsiveness) were included, consistency begins to drop. Buttons are labeled differently and are different sizes and colours. Responsiveness, though apparently functioning correctly in all three instances, is structured very differently. +My main takeaway from this exercise is a nagging feeling that it sucked the joy out of the experience of creating this simple page. \ No newline at end of file