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 @@
| Item | +Price | +Rating | +
|---|
Some optional stuff.
+\ 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 @@ + + +
+ + + +
+ \ 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 @@ + + + +
+ + + +
+ + + + + +
+ +