diff --git a/.gitignore b/.gitignore index c4d4e3a1..7f134d93 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ node_modules **/node_modules .DS_Store -**/.DS_Store \ No newline at end of file +**/.DS_Store +package-lock.json \ No newline at end of file diff --git a/Sprint-1/destructuring/exercise-1/exercise.js b/Sprint-1/destructuring/exercise-1/exercise.js index 1ff2ac5c..90eb4795 100644 --- a/Sprint-1/destructuring/exercise-1/exercise.js +++ b/Sprint-1/destructuring/exercise-1/exercise.js @@ -6,7 +6,7 @@ const personOne = { // Update the parameter to this function to make it work. // Don't change anything else. -function introduceYourself(___________________________) { +function introduceYourself({name, age, favouriteFood}) { console.log( `Hello, my name is ${name}. I am ${age} years old and my favourite food is ${favouriteFood}.` ); diff --git a/Sprint-1/destructuring/exercise-2/exercise.js b/Sprint-1/destructuring/exercise-2/exercise.js index e11b75eb..34ec7891 100644 --- a/Sprint-1/destructuring/exercise-2/exercise.js +++ b/Sprint-1/destructuring/exercise-2/exercise.js @@ -70,3 +70,26 @@ let hogwarts = [ occupation: "Teacher", }, ]; + +let gryffindor = ""; +let teatcherDog = ""; +for (let witcher of hogwarts) { + const { + firstName: name, + lastName: surname, + house, + pet, + occupation, + } = witcher; + + const text = name + " " + surname + "\n"; + if (house === "Gryffindor") { + gryffindor += text; + if (pet && occupation === "Teacher") { + teatcherDog += text; + } + } +} + +console.log(`\nGryffindor Residents:\n${gryffindor}`); +console.log(`\nGryffindor Teacher who has pet:\n${teatcherDog}`); diff --git a/Sprint-1/destructuring/exercise-3/exercise.js b/Sprint-1/destructuring/exercise-3/exercise.js index b3a36f4e..3ba41c49 100644 --- a/Sprint-1/destructuring/exercise-3/exercise.js +++ b/Sprint-1/destructuring/exercise-3/exercise.js @@ -6,3 +6,13 @@ let order = [ { itemName: "Hot Coffee", quantity: 2, unitPricePence: 100 }, { itemName: "Hash Brown", quantity: 4, unitPricePence: 40 }, ]; +const setPrice = (pricePence) => (pricePence / 100).toFixed(2) +let total = 0; +console.log(`${("QTY").padEnd(7)}${"ITEM".padEnd( 20)}TOTAL`); +for (let item of order){ + const {itemName, quantity, unitPricePence} = item; + const sousTotal = (quantity * unitPricePence); + total += sousTotal; + console.log(`${(quantity+"").padEnd(7)}${itemName.padEnd(20)}${setPrice(sousTotal)}`); +} +console.log(`\n${("TOTAL").padEnd(26)}${setPrice(total)}`); diff --git a/challenges/challenge-cowsay-two/package.json b/challenges/challenge-cowsay-two/package.json new file mode 100644 index 00000000..65b9ee96 --- /dev/null +++ b/challenges/challenge-cowsay-two/package.json @@ -0,0 +1,27 @@ +{ + "name": "challenges", + "version": "1.0.0", + "description": "Javascript and node.js challenges.", + "keywords": [ + "javascript", + "HYF" + ], + "homepage": "https://github.com/serotonine/HYF-Module-Data-Flows#readme", + "bugs": { + "url": "https://github.com/serotonine/HYF-Module-Data-Flows/issues" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/serotonine/HYF-Module-Data-Flows.git" + }, + "license": "ISC", + "author": "Serotonine", + "type": "module", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "dependencies": { + "readline-sync": "^1.4.10" + } +} diff --git a/challenges/challenge-cowsay-two/solution1.js b/challenges/challenge-cowsay-two/solution1.js index a7f2416b..24dcca91 100644 --- a/challenges/challenge-cowsay-two/solution1.js +++ b/challenges/challenge-cowsay-two/solution1.js @@ -4,27 +4,43 @@ // https://nodejs.dev/learn/nodejs-accept-arguments-from-the-command-line // ================= -// 1. Accept arguments +function drawBubble(str, lg){ + if(!str){return} + let bubble = ""; + bubble += ` ${"–".repeat(lg + 2)} \n`; + bubble += `< ${str} >\n`; + bubble += ` ${"-".repeat(lg + 2)}`; + console.log(bubble); -// how will you accept arguments? - -// 2. Make supplies for our speech bubble - -let topLine = '_'; -let bottomLine = '-'; -let saying = ''; - -// 3. Make a cow that takes a string - -function cowsay(saying) { -// how will you make the speech bubble contain the text? - -// where will the cow picture go? +} -// how will you account for the parameter being empty? +function drawCow(talk, lg){ + const prefix = (" ").repeat(lg + 2 - Math.round(lg / 2)); + const stucks = [ + `${talk?"\\ ^——^":" ^——^"}\n`, + `${talk?" \\ (oo)\________":" (oo)\________"}\n`, + ` (__)\\ )\\/\\\n`, + ` ||----w |\n`, + ` || ||` + ].map((row)=> prefix + row); +console.log(stucks.join("")); } -//4. Pipe argument into cowsay function and return a cow +function cowsay() { + // Get console argument. + const talk = process.argv.at(2); + // If no argument. + if(!talk){ + console.log("No talk"); + return; + } + const lg = talk.length; + drawCow(false, lg); + setTimeout(()=>{ + drawBubble(talk,lg); + drawCow(true, lg); + }, 1000); +} -// how will you log this to the console? +cowsay(); diff --git a/challenges/challenge-cowsay-two/solution2.js b/challenges/challenge-cowsay-two/solution2.js index 8aca8572..ff7e9a12 100644 --- a/challenges/challenge-cowsay-two/solution2.js +++ b/challenges/challenge-cowsay-two/solution2.js @@ -1,18 +1,48 @@ +import readlineSync from 'readline-sync'; // ================= // Stripped down cowsayer CLI, -// no libraries or arguments -// https://nodejs.dev/learn/accept-input-from-the-command-line-in-nodejs +// no libraries +// https://nodejs.dev/learn/nodejs-accept-arguments-from-the-command-line // ================= -// 1. Make a command line interface. +function drawBubble(str, lg){ + if(!str){return} + let bubble = ""; + bubble += ` ${"–".repeat(lg + 2)} \n`; + bubble += `< ${str} >\n`; + bubble += ` ${"-".repeat(lg + 2)}`; + console.log(bubble); -// 2. Make supplies for our speech bubble +} + +function drawCow(talk, lg=0){ + const prefix = (" ").repeat(lg + 2 - Math.round(lg / 2)); + const stucks = [ + `${talk?"\\ ^——^":" ^——^"}\n`, + `${talk?" \\ (oo)\________":" (oo)\________"}\n`, + ` (__)\\ )\\/\\\n`, + ` ||----w |\n`, + ` || ||` + ].map((row)=> prefix + row); +console.log(stucks.join("")); -// 3. Make a cow that takes a string +} -const cow = (saying) => { - // how did you make the cow before? +function cowsay() { + drawCow(false); + // Get console argument. + const talk = readlineSync.question('Wazz up Miss Cow? '); + // If no argument. + if(!talk){ + console.log("Miss Cow is not very talkative..."); + return; + } + const lg = talk.length; + + setTimeout(()=>{ + drawBubble(talk,lg); + drawCow(true, lg); + }, 1000); } -// 4. Use readline to get a string from the terminal -// (with a prompt so it's clearer what we want) \ No newline at end of file +cowsay(); diff --git a/challenges/challenge-weather-app/assets/globals.css b/challenges/challenge-weather-app/assets/globals.css index c9742ea5..83ae8249 100644 --- a/challenges/challenge-weather-app/assets/globals.css +++ b/challenges/challenge-weather-app/assets/globals.css @@ -12,10 +12,11 @@ :root { --thumb-w: 80px; - --thumb-h: 45px; + --thumb-h: 80px; --thumbs-px: 10px; --thumbs-py: 10px; --thumbs-h: calc(var(--thumb-h) + (var(--thumbs-py) * 2)); + --color-main:oklab(30.993% -0.01087 -0.01628); } html, diff --git a/challenges/challenge-weather-app/assets/styles.css b/challenges/challenge-weather-app/assets/styles.css index 9046ba1b..248eb903 100644 --- a/challenges/challenge-weather-app/assets/styles.css +++ b/challenges/challenge-weather-app/assets/styles.css @@ -1,7 +1,7 @@ .content { + background-color: var(--color-main); display: grid; grid-template-rows: auto 1fr auto auto auto; - height: 100vh; overflow: hidden; } @@ -35,15 +35,14 @@ display: grid; justify-content: center; align-content: center; - overflow: hidden; position: relative; margin: 20px 0; } .photo::before { - content: "loading"; - + content: "loading..."; + color:white; display: grid; justify-content: center; align-content: center; @@ -58,6 +57,9 @@ text-transform: uppercase; letter-spacing: 3px; } +.photo.init::before{ + content: "Please search a location"; +} .photo__dummy, .photo > img { @@ -220,11 +222,11 @@ /*----------------------------------------------------------------------------*/ @media (min-width: 768px) { .title { - font-weight: 100; + font-weight: 400; } .thumbs { - justify-content: center; + /* justify-content: center; */ } .controls { diff --git a/challenges/challenge-weather-app/index.html b/challenges/challenge-weather-app/index.html index b1add346..4ea2a778 100644 --- a/challenges/challenge-weather-app/index.html +++ b/challenges/challenge-weather-app/index.html @@ -21,7 +21,9 @@

-
+
+ +

@@ -32,7 +34,8 @@

-
+
+