From 0b6ae3c8902d0aba557084de84d963c83cdb03c6 Mon Sep 17 00:00:00 2001 From: Yanina Amatore Date: Wed, 30 Nov 2022 15:19:25 +1300 Subject: [PATCH 01/13] initial commit --- 01-Fundamentals-Part-1/script.js | 0 01-Fundamentals-Part-1/starter/index.html | 6 +++++- 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 01-Fundamentals-Part-1/script.js diff --git a/01-Fundamentals-Part-1/script.js b/01-Fundamentals-Part-1/script.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/01-Fundamentals-Part-1/starter/index.html b/01-Fundamentals-Part-1/starter/index.html index 59529c7923..2d6f9cd226 100755 --- a/01-Fundamentals-Part-1/starter/index.html +++ b/01-Fundamentals-Part-1/starter/index.html @@ -5,7 +5,7 @@ JavaScript Fundamentals – Part 1 - +

JavaScript Fundamentals – Part 1

From 1917f2ce90263add3e4f0c8e8d1b01cc8f41da56 Mon Sep 17 00:00:00 2001 From: Yanina Amatore Date: Thu, 1 Dec 2022 12:25:41 +1300 Subject: [PATCH 02/13] challenge 1 --- 01-Fundamentals-Part-1/script.js | 0 01-Fundamentals-Part-1/starter/index.html | 8 ++-- 01-Fundamentals-Part-1/starter/script.js | 46 +++++++++++++++++++++++ 3 files changed, 49 insertions(+), 5 deletions(-) delete mode 100644 01-Fundamentals-Part-1/script.js create mode 100644 01-Fundamentals-Part-1/starter/script.js diff --git a/01-Fundamentals-Part-1/script.js b/01-Fundamentals-Part-1/script.js deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/01-Fundamentals-Part-1/starter/index.html b/01-Fundamentals-Part-1/starter/index.html index 2d6f9cd226..47df753e84 100755 --- a/01-Fundamentals-Part-1/starter/index.html +++ b/01-Fundamentals-Part-1/starter/index.html @@ -5,7 +5,7 @@ JavaScript Fundamentals – Part 1 - + - +

JavaScript Fundamentals – Part 1

+ diff --git a/01-Fundamentals-Part-1/starter/script.js b/01-Fundamentals-Part-1/starter/script.js new file mode 100644 index 0000000000..4c0643149d --- /dev/null +++ b/01-Fundamentals-Part-1/starter/script.js @@ -0,0 +1,46 @@ +//Mark and John are trying to compare their BMI (Body Mass Index), which is +// calculated using the formula: +// BMI = mass / height ** 2 = mass / (height * height) (mass in kg +// and height in meter). +// Your tasks: +// 1. Store Mark's and John's mass and height in variables +// 2. Calculate both their BMIs using the formula (you can even implement both +// versions) +// 3. Create a Boolean variable 'markHigherBMI' containing information about +// whether Mark has a higher BMI than John. +// Test data: +// § Data 1: Marks weights 78 kg and is 1.69 m tall. John weights 92 kg and is 1.95 +// m tall. +// § Data 2: Marks weights 95 kg and is 1.88 m tall. John weights 85 kg and is 1.76 +// m tall. + +const markHeight = 1.69 +const markWeight = 78 + +const johnHeight = 1.95 +const johnWeight = 92 + +const markBMI = markWeight /(markHeight**2) +console.log('mark', markBMI) + +const johnBMI= johnWeight /(johnHeight**2) +console.log('john', johnBMI) + +const markHeigherBMI = markBMI > johnBMI +console.log('markHeigher', markHeigherBMI) + +//data 2 +const heightMark = 1.88 +const massMark = 95 + +const heightJohn = 1.76 +const massJohn = 85 + +const BIMmark = massMark / heightMark**2 +console.log('mark', BIMmark) + +const BMIJohn= massJohn/ heightJohn**2 +console.log('john', BMIJohn) + +const BIMmarkHigher = BIMmark > BMIJohn +console.log('higher', BIMmarkHigher) \ No newline at end of file From db0d399e0fcc6c55b23a010e8d5aac8419cdc015 Mon Sep 17 00:00:00 2001 From: Yanina Amatore Date: Thu, 1 Dec 2022 13:45:48 +1300 Subject: [PATCH 03/13] challenge 2 --- 01-Fundamentals-Part-1/starter/script.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/01-Fundamentals-Part-1/starter/script.js b/01-Fundamentals-Part-1/starter/script.js index 4c0643149d..87639127d9 100644 --- a/01-Fundamentals-Part-1/starter/script.js +++ b/01-Fundamentals-Part-1/starter/script.js @@ -14,6 +14,12 @@ // § Data 2: Marks weights 95 kg and is 1.88 m tall. John weights 85 kg and is 1.76 // m tall. +// Your tasks: +// 1. Print a nice output to the console, saying who has the higher BMI. The message +// is either "Mark's BMI is higher than John's!" or "John's BMI is higher than Mark's!" +// 2. Use a template literal to include the BMI values in the outputs. Example: "Mark's +// BMI (28.3) is higher than John's (23.9)!" + const markHeight = 1.69 const markWeight = 78 @@ -29,6 +35,13 @@ console.log('john', johnBMI) const markHeigherBMI = markBMI > johnBMI console.log('markHeigher', markHeigherBMI) +if (markHeigherBMI){ + console.log(`Mark's BMI is higher`) +}else{ + console.log(`john's BMI is higher`) +} + + //data 2 const heightMark = 1.88 const massMark = 95 @@ -43,4 +56,9 @@ const BMIJohn= massJohn/ heightJohn**2 console.log('john', BMIJohn) const BIMmarkHigher = BIMmark > BMIJohn -console.log('higher', BIMmarkHigher) \ No newline at end of file +console.log('higher', BIMmarkHigher) +if (BIMmarkHigher){ + console.log(`Mark's BMI is higher`) +}else{ + console.log(`john's BMI is higher`) +} \ No newline at end of file From 41f4a98cbf5b7fdfb83332e82702ac3ac2aa2d39 Mon Sep 17 00:00:00 2001 From: Yanina Amatore Date: Mon, 12 Dec 2022 12:54:38 +1300 Subject: [PATCH 04/13] Challenge 3 --- 01-Fundamentals-Part-1/starter/script.js | 137 ++++++++++++++++++----- 1 file changed, 107 insertions(+), 30 deletions(-) diff --git a/01-Fundamentals-Part-1/starter/script.js b/01-Fundamentals-Part-1/starter/script.js index 87639127d9..39b2ae6ff8 100644 --- a/01-Fundamentals-Part-1/starter/script.js +++ b/01-Fundamentals-Part-1/starter/script.js @@ -20,45 +20,122 @@ // 2. Use a template literal to include the BMI values in the outputs. Example: "Mark's // BMI (28.3) is higher than John's (23.9)!" -const markHeight = 1.69 -const markWeight = 78 +// const markHeight = 1.69 +// const markWeight = 78 -const johnHeight = 1.95 -const johnWeight = 92 +// const johnHeight = 1.95 +// const johnWeight = 92 -const markBMI = markWeight /(markHeight**2) -console.log('mark', markBMI) +// const markBMI = markWeight /(markHeight**2) +// console.log('mark', markBMI) -const johnBMI= johnWeight /(johnHeight**2) -console.log('john', johnBMI) +// const johnBMI= johnWeight /(johnHeight**2) +// console.log('john', johnBMI) -const markHeigherBMI = markBMI > johnBMI -console.log('markHeigher', markHeigherBMI) +// const markHeigherBMI = markBMI > johnBMI +// console.log('markHeigher', markHeigherBMI) -if (markHeigherBMI){ - console.log(`Mark's BMI is higher`) -}else{ - console.log(`john's BMI is higher`) +// if (markHeigherBMI){ +// console.log(`Mark's BMI is higher`) +// }else{ +// console.log(`john's BMI is higher`) +// } + +//data 2 +// const heightMark = 1.88 +// const massMark = 95 + +// const heightJohn = 1.76 +// const massJohn = 85 + +// const BIMmark = massMark / heightMark**2 +// console.log('mark', BIMmark) + +// const BMIJohn= massJohn/ heightJohn**2 +// console.log('john', BMIJohn) + +// const BIMmarkHigher = BIMmark > BMIJohn +// console.log('higher', BIMmarkHigher) +// if (BIMmarkHigher){ +// console.log(`Mark's BMI is higher`) +// }else{ +// console.log(`john's BMI is higher`) +// } + +// Challenge #3 + +// Dolphins & Koalas + +// Calculate the average score foreach team +// compare the teams' average score to determine the winner and console.log - test for a draw as well + +const dolphinsArray = [96, 108, 89] + +const averageD = dolphinsArray.reduce((a, b) => a + b, 0) / dolphinsArray.length + +console.log('dolphins', averageD) + +const koalasArray = [88, 91, 110] + +const averageK = koalasArray.reduce((a, b) => a + b, 0) / koalasArray.length + +console.log(`Koala's`, averageK) + +if (averageK > averageD) { + console.log(`Koalas Win`, averageK) +} else if (averageD > averageK) { + console.log(`Dolphins win`, averageD) +} else { + console.log(`There's a draw`) } +//Bonus 1 -//data 2 -const heightMark = 1.88 -const massMark = 95 +const arrDolphins = [97, 112, 101] + +const d_Average = arrDolphins.reduce((a, b) => a + b, 0) / arrDolphins.length + +console.log('dolphins2', d_Average) + +const arrKoalas = [109, 95, 123] + +const k_AverageK = arrKoalas.reduce((a, b) => a + b, 0) / arrKoalas.length + +console.log(`Koalas2`, k_AverageK) -const heightJohn = 1.76 -const massJohn = 85 +const isOverOneHundred = true -const BIMmark = massMark / heightMark**2 -console.log('mark', BIMmark) +if (d_Average > k_AverageK && d_Average > 100) { + console.log(`Dolphins Win`, d_Average) +} else if (k_AverageK > averageD && k_AverageK > 100) { + console.log(`Bonus 1 Koalas win and > 100`, k_AverageK) +} else { + console.log(`There's a draw`) +} + +// Bonus 2 + +const dolphins_Array = [97, 112, 101] + +const dolAverage = + dolphins_Array.reduce((a, b) => a + b, 0) / dolphins_Array.length -const BMIJohn= massJohn/ heightJohn**2 -console.log('john', BMIJohn) +console.log('dolphins3', dolAverage) -const BIMmarkHigher = BIMmark > BMIJohn -console.log('higher', BIMmarkHigher) -if (BIMmarkHigher){ - console.log(`Mark's BMI is higher`) -}else{ - console.log(`john's BMI is higher`) -} \ No newline at end of file +const koalas_Array = [109, 95, 106] + +const koaAverageK = + koalas_Array.reduce((a, b) => a + b, 0) / koalas_Array.length +console.log(`Koalas3`, koaAverageK) + +if (dolAverage >= 100 && dolAverage > koaAverageK) { + console.log(`Bonus 2 Dolphins Win`, dolAverage) +} else if (koaAverageK >= 100 && koaAverageK > dolAverage) { + console.log(`Bonus 2 Koalas win `, k_AverageK) +} else if (koaAverageK >= 100 && koaAverageK >= 100 && koaAverageK === dolAverage) { + console.log(`Bonus 2 DRAW`, k_AverageK) +}else if (koaAverageK < 100) { + console.log(`Bonus 3 koalas <100`, koaAverageK) +} else if (dolAverage < 100) { + console.log(`Bonus 3 dolphins <100`, dolAverage) +} From 31f0266db77141d3f9fda7d39884bc0200f83f46 Mon Sep 17 00:00:00 2001 From: Yanina Amatore Date: Mon, 9 Jan 2023 14:48:59 +1300 Subject: [PATCH 05/13] coding challenge 3 --- 01-Fundamentals-Part-1/starter/script.js | 129 +++++++++++++++-------- 1 file changed, 84 insertions(+), 45 deletions(-) diff --git a/01-Fundamentals-Part-1/starter/script.js b/01-Fundamentals-Part-1/starter/script.js index 39b2ae6ff8..ca3ba98ec6 100644 --- a/01-Fundamentals-Part-1/starter/script.js +++ b/01-Fundamentals-Part-1/starter/script.js @@ -69,73 +69,112 @@ // Calculate the average score foreach team // compare the teams' average score to determine the winner and console.log - test for a draw as well -const dolphinsArray = [96, 108, 89] +// const dolphinsArray = [96, 108, 89] -const averageD = dolphinsArray.reduce((a, b) => a + b, 0) / dolphinsArray.length +// const averageD = dolphinsArray.reduce((a, b) => a + b, 0) / dolphinsArray.length -console.log('dolphins', averageD) +// console.log('dolphins', averageD) -const koalasArray = [88, 91, 110] +// const koalasArray = [88, 91, 110] -const averageK = koalasArray.reduce((a, b) => a + b, 0) / koalasArray.length +// const averageK = koalasArray.reduce((a, b) => a + b, 0) / koalasArray.length -console.log(`Koala's`, averageK) +// console.log(`Koala's`, averageK) -if (averageK > averageD) { - console.log(`Koalas Win`, averageK) -} else if (averageD > averageK) { - console.log(`Dolphins win`, averageD) -} else { - console.log(`There's a draw`) -} +// if (averageK > averageD) { +// console.log(`Koalas Win`, averageK) +// } else if (averageD > averageK) { +// console.log(`Dolphins win`, averageD) +// } else { +// console.log(`There's a draw`) +// } //Bonus 1 -const arrDolphins = [97, 112, 101] +// const arrDolphins = [97, 112, 101] -const d_Average = arrDolphins.reduce((a, b) => a + b, 0) / arrDolphins.length +// const d_Average = arrDolphins.reduce((a, b) => a + b, 0) / arrDolphins.length -console.log('dolphins2', d_Average) +// console.log('dolphins2', d_Average) -const arrKoalas = [109, 95, 123] +// const arrKoalas = [109, 95, 123] -const k_AverageK = arrKoalas.reduce((a, b) => a + b, 0) / arrKoalas.length +// const k_AverageK = arrKoalas.reduce((a, b) => a + b, 0) / arrKoalas.length -console.log(`Koalas2`, k_AverageK) +// console.log(`Koalas2`, k_AverageK) -const isOverOneHundred = true +// const isOverOneHundred = true -if (d_Average > k_AverageK && d_Average > 100) { - console.log(`Dolphins Win`, d_Average) -} else if (k_AverageK > averageD && k_AverageK > 100) { - console.log(`Bonus 1 Koalas win and > 100`, k_AverageK) -} else { - console.log(`There's a draw`) -} +// if (d_Average > k_AverageK && d_Average > 100) { +// console.log(`Dolphins Win`, d_Average) +// } else if (k_AverageK > averageD && k_AverageK > 100) { +// console.log(`Bonus 1 Koalas win and > 100`, k_AverageK) +// } else { +// console.log(`There's a draw`) +// } // Bonus 2 -const dolphins_Array = [97, 112, 101] +// const dolphins_Array = [97, 112, 101] + +// const dolAverage = +// dolphins_Array.reduce((a, b) => a + b, 0) / dolphins_Array.length + +// console.log('dolphins3', dolAverage) + +// const koalas_Array = [109, 95, 106] + +// const koaAverageK = +// koalas_Array.reduce((a, b) => a + b, 0) / koalas_Array.length +// console.log(`Koalas3`, koaAverageK) + +// if (dolAverage >= 100 && dolAverage > koaAverageK) { +// console.log(`Bonus 2 Dolphins Win`, dolAverage) +// } else if (koaAverageK >= 100 && koaAverageK > dolAverage) { +// console.log(`Bonus 2 Koalas win `, k_AverageK) +// } else if (koaAverageK >= 100 && koaAverageK >= 100 && koaAverageK === dolAverage) { +// console.log(`Bonus 2 DRAW`, k_AverageK) +// }else if (koaAverageK < 100) { +// console.log(`Bonus 3 koalas <100`, koaAverageK) +// } else if (dolAverage < 100) { +// console.log(`Bonus 3 dolphins <100`, dolAverage) +// } + + +// Challenge 4 -const dolAverage = - dolphins_Array.reduce((a, b) => a + b, 0) / dolphins_Array.length +// 50-300 15% else 20% -console.log('dolphins3', dolAverage) -const koalas_Array = [109, 95, 106] +// const bill= 275 +// const bill= 40 +// const bill =430 -const koaAverageK = - koalas_Array.reduce((a, b) => a + b, 0) / koalas_Array.length -console.log(`Koalas3`, koaAverageK) +// const tip = bill >=50 && bill <=300 ? bill * 0.2 : bill * 0.15 +// console.log('tip: ', tip) +// const total = bill + tip +// console.log(`The bill was ${bill}, the tip was ${tip}, and the total value +// ${total}`) -if (dolAverage >= 100 && dolAverage > koaAverageK) { - console.log(`Bonus 2 Dolphins Win`, dolAverage) -} else if (koaAverageK >= 100 && koaAverageK > dolAverage) { - console.log(`Bonus 2 Koalas win `, k_AverageK) -} else if (koaAverageK >= 100 && koaAverageK >= 100 && koaAverageK === dolAverage) { - console.log(`Bonus 2 DRAW`, k_AverageK) -}else if (koaAverageK < 100) { - console.log(`Bonus 3 koalas <100`, koaAverageK) -} else if (dolAverage < 100) { - console.log(`Bonus 3 dolphins <100`, dolAverage) + +const average = function (score1, score2, score3){ + return (score1, score2, score3)/3 } + +const dolAverage= average(96, 108, 89) +console.log('dolAverage', dolAverage) + +const KoalaAverage= average(88, 91, 110) +console.log('KoalaAverage', KoalaAverage) + +function declareWinner(dolAverage, KoalaAverage){ + if (dolAverage == KoalaAverage){ + console.log (`${dolAverage, KoalaAverage}It's a Tie, there's no winner`) + } else if (dolAverage > KoalaAverage){ + console.log (`score: ${dolAverage} dolphins Wins`) + } else{ + console.log (`score: ${KoalaAverage} Koalas Wins`) + } +} + +declareWinner(dolAverage, KoalaAverage) \ No newline at end of file From 9b467beb30ad23c54498b8a5e4e773f41290c32f Mon Sep 17 00:00:00 2001 From: Yanina Amatore Date: Wed, 11 Jan 2023 14:08:13 +1300 Subject: [PATCH 06/13] Challenge 2 completed --- 01-Fundamentals-Part-1/starter/script.js | 22 ------ 02-Fundamentals-Part-2/starter/script.js | 85 ++++++++++++++++++++++++ 2 files changed, 85 insertions(+), 22 deletions(-) diff --git a/01-Fundamentals-Part-1/starter/script.js b/01-Fundamentals-Part-1/starter/script.js index ca3ba98ec6..5b52ccefe2 100644 --- a/01-Fundamentals-Part-1/starter/script.js +++ b/01-Fundamentals-Part-1/starter/script.js @@ -156,25 +156,3 @@ // console.log(`The bill was ${bill}, the tip was ${tip}, and the total value // ${total}`) - -const average = function (score1, score2, score3){ - return (score1, score2, score3)/3 -} - -const dolAverage= average(96, 108, 89) -console.log('dolAverage', dolAverage) - -const KoalaAverage= average(88, 91, 110) -console.log('KoalaAverage', KoalaAverage) - -function declareWinner(dolAverage, KoalaAverage){ - if (dolAverage == KoalaAverage){ - console.log (`${dolAverage, KoalaAverage}It's a Tie, there's no winner`) - } else if (dolAverage > KoalaAverage){ - console.log (`score: ${dolAverage} dolphins Wins`) - } else{ - console.log (`score: ${KoalaAverage} Koalas Wins`) - } -} - -declareWinner(dolAverage, KoalaAverage) \ No newline at end of file diff --git a/02-Fundamentals-Part-2/starter/script.js b/02-Fundamentals-Part-2/starter/script.js index e69de29bb2..8acfc7a3bf 100755 --- a/02-Fundamentals-Part-2/starter/script.js +++ b/02-Fundamentals-Part-2/starter/script.js @@ -0,0 +1,85 @@ +/////////////////////////////////////// +// Coding Challenge #1 + +/* +Back to the two gymnastics teams, the Dolphins and the Koalas! There is a new gymnastics discipline, which works differently. +Each team competes 3 times, and then the average of the 3 scores is calculated (so one average score per team). +A team ONLY wins if it has at least DOUBLE the average score of the other team. Otherwise, no team wins! + +1. Create an arrow function 'calcAverage' to calculate the average of 3 scores +2. Use the function to calculate the average for both teams +3. Create a function 'checkWinner' that takes the average score of each team as parameters ('avgDolhins' and 'avgKoalas'), and then logs the winner to the console, together with the victory points, according to the rule above. Example: "Koalas win (30 vs. 13)". +4. Use the 'checkWinner' function to determine the winner for both DATA 1 and DATA 2. +5. Ignore draws this time. + +TEST DATA 1: Dolphins score 44, 23 and 71. Koalas score 65, 54 and 49 +TEST DATA 2: Dolphins score 85, 54 and 41. Koalas score 23, 34 and 27 + +HINT: To calculate average of 3 values, add them all together and divide by 3 +HINT: To check if number A is at least double number B, check for A >= 2 * B. Apply this to the team's average scores 😉 + +GOOD LUCK 😀 +*/ + +const calcAverage= (score1, score2, score3) => (score1 + score2+ score3)/3 + +// TEST DATA 1: +let avgDolhins= calcAverage(44, 23, 71) +let avgKoalas= calcAverage(65, 54, 49) + +console.log('dolAverage', avgDolhins, 'KoalaAverage', avgKoalas) + +const checkWinner = function(avgDolhins, avgKoalas){ + if (avgDolhins >= 2 * avgKoalas){ + console.log (`Dolphins Win - ( ${avgDolhins} vs. ${avgKoalas})`) + } else if (avgKoalas >= 2 * avgDolhins){ + console.log (`Koalas Win - ( ${avgKoalas} vs. ${avgDolhins})`) + }else{ + console.log (`There's no winner`) + } + } + + checkWinner(avgDolhins, avgKoalas) + +// TEST DATA 2: Dolphins score 85, 54 and 41. Koalas score 23, 34 and 27 + +avgDolhins= calcAverage(85, 54, 41) +avgKoalas= calcAverage(23, 34, 27) +console.log('dolAverage', avgDolhins, 'KoalaAverage', avgKoalas) + +checkWinner(avgDolhins, avgKoalas) + + +/////////////////////////////////////// +// Coding Challenge #2 + +/* +Steven is still building his tip calculator, using the same rules as before: Tip 15% of the bill if the bill value is between 50 and 300, and if the value is different, the tip is 20%. + +1. Write a function 'calcTip' that takes any bill value as an input and returns the corresponding tip, calculated based on the rules above (you can check out the code from first tip calculator challenge if you need to). Use the function type you like the most. Test the function using a bill value of 100. +2. And now let's use arrays! So create an array 'bills' containing the test data below. +3. Create an array 'tips' containing the tip value for each bill, calculated from the function you created before. +4. BONUS: Create an array 'total' containing the total values, so the bill + tip. + +TEST DATA: 125, 555 and 44 + +HINT: Remember that an array needs a value in each position, and that value can actually be the returned value of a function! So you can just call a function as array values (so don't store the tip values in separate variables first, but right in the new array) 😉 + +GOOD LUCK 😀 +*/ + +const calcTip = function (bill){ + if (bill >= 50 && bill <=300){ + return bill * 0.15 + } else{ + return bill * 0.20 + } +} +// arrow func && ternary +// const calcTip = (bill) => bill >=50 && bill <=300 ? bill * 0.15 : bill * 0.20 + +const bills = [125, 55, 44] +let tips = [ calcTip(bills[0]), calcTip(bills[1]), calcTip(bills[2])] + +let total = [ bills[0]+ tips[0], bills[1] + tips[1], bills[2] + tips[2]] +console.log('tips arr', tips, 'total', total) \ No newline at end of file From df795216197780b3cf6892ad35ecae71ec8f3258 Mon Sep 17 00:00:00 2001 From: Yanina Amatore Date: Wed, 11 Jan 2023 15:48:30 +1300 Subject: [PATCH 07/13] challenge 3 completed --- 02-Fundamentals-Part-2/starter/script.js | 71 +++++++++++++++++++++++- 1 file changed, 70 insertions(+), 1 deletion(-) diff --git a/02-Fundamentals-Part-2/starter/script.js b/02-Fundamentals-Part-2/starter/script.js index 8acfc7a3bf..01e3d1e0a1 100755 --- a/02-Fundamentals-Part-2/starter/script.js +++ b/02-Fundamentals-Part-2/starter/script.js @@ -82,4 +82,73 @@ const bills = [125, 55, 44] let tips = [ calcTip(bills[0]), calcTip(bills[1]), calcTip(bills[2])] let total = [ bills[0]+ tips[0], bills[1] + tips[1], bills[2] + tips[2]] -console.log('tips arr', tips, 'total', total) \ No newline at end of file +console.log('tips arr', tips, 'total', total) + + + // challenge video 43 + + const jonas = { + firstName: 'Jonas', + lastName: 'Schmedtmann', + birthYear: 1991, + job: 'teacher', + friends: ['Michael', 'Peter', 'Steven'], + hasDriversLicense: false, + calcAge: function(){ + this.age = 2037 - this.birthYear + return this.age + }, + getSummary: function(){ + return `${this.firstName} is a ${this.calcAge()} y.o ${this.job} & he has ${this.hasDriversLicense? 'a ': 'no'}drivers license. ` + } +}; + + + +// console.log(`${jonas.firstName} has ${jonas.friends.length} friends, and his best friend is called ${jonas.friends[0]}`) + + + +console.log(jonas.getSummary()) + +/////////////////////////////////////// +// Coding Challenge #3 + +/* +Let's go back to Mark and John comparing their BMIs! This time, let's use objects to implement the calculations! Remember: BMI = mass / height ** 2 = mass / (height * height). (mass in kg and height in meter) + +1. For each of them, create an object with properties for their full name, mass, and height (Mark Miller and John Smith) +2. Create a 'calcBMI' method on each object to calculate the BMI (the same method on both objects). Store the BMI value to a property, and also return it from the method. +3. Log to the console who has the higher BMI, together with the full name and the respective BMI. Example: "John Smith's BMI (28.3) is higher than Mark Miller's (23.9)!" + +TEST DATA: Marks weights 78 kg and is 1.69 m tall. John weights 92 kg and is 1.95 m tall. + +GOOD LUCK 😀 +*/ + +const mark ={ + firstName: 'Mark', + lastName: 'Miller', + height: 1.69, + weight: 78, + calcBMI: function() { + this.bmi = Math.round(this.weight / this.height ** 2 ) + return this.bmi + } +} + +const john ={ + firstName: 'John', + lastName: 'Smith', + height: 1.95, + weight: 92, + calcBMI: function() { + this.bmi = Math.round(this.weight / this.height ** 2 ) + return this.bmi + } +} + +mark.calcBMI(); +john.calcBMI(); + +console.log( mark.bmi > john.bmi ? `${mark.firstName} BMI: (${mark.bmi}) is higher than ${john.firstName}'s BMI: (${john.bmi})`: `${john.firstName}'s BMI ${john.bmi} is higher than ${mark.firstName} BMI (${mark.bmi})` ) \ No newline at end of file From fde2a08890fea6846568225b341c99c33a1c0967 Mon Sep 17 00:00:00 2001 From: Yanina Amatore Date: Thu, 12 Jan 2023 15:28:31 +1300 Subject: [PATCH 08/13] ex LECTURE: Dot vs. Bracket Notation --- 02-Fundamentals-Part-2/starter/script.js | 177 ++++++++++++++--------- 1 file changed, 105 insertions(+), 72 deletions(-) diff --git a/02-Fundamentals-Part-2/starter/script.js b/02-Fundamentals-Part-2/starter/script.js index 01e3d1e0a1..75c43548a8 100755 --- a/02-Fundamentals-Part-2/starter/script.js +++ b/02-Fundamentals-Part-2/starter/script.js @@ -21,33 +21,33 @@ HINT: To check if number A is at least double number B, check for A >= 2 * B. Ap GOOD LUCK 😀 */ -const calcAverage= (score1, score2, score3) => (score1 + score2+ score3)/3 +// const calcAverage= (score1, score2, score3) => (score1 + score2+ score3)/3 // TEST DATA 1: -let avgDolhins= calcAverage(44, 23, 71) -let avgKoalas= calcAverage(65, 54, 49) - -console.log('dolAverage', avgDolhins, 'KoalaAverage', avgKoalas) - -const checkWinner = function(avgDolhins, avgKoalas){ - if (avgDolhins >= 2 * avgKoalas){ - console.log (`Dolphins Win - ( ${avgDolhins} vs. ${avgKoalas})`) - } else if (avgKoalas >= 2 * avgDolhins){ - console.log (`Koalas Win - ( ${avgKoalas} vs. ${avgDolhins})`) - }else{ - console.log (`There's no winner`) - } - } +// let avgDolhins= calcAverage(44, 23, 71) +// let avgKoalas= calcAverage(65, 54, 49) + +// console.log('dolAverage', avgDolhins, 'KoalaAverage', avgKoalas) + +// const checkWinner = function(avgDolhins, avgKoalas){ +// if (avgDolhins >= 2 * avgKoalas){ +// console.log (`Dolphins Win - ( ${avgDolhins} vs. ${avgKoalas})`) +// } else if (avgKoalas >= 2 * avgDolhins){ +// console.log (`Koalas Win - ( ${avgKoalas} vs. ${avgDolhins})`) +// }else{ +// console.log (`There's no winner`) +// } +// } - checkWinner(avgDolhins, avgKoalas) +// checkWinner(avgDolhins, avgKoalas) // TEST DATA 2: Dolphins score 85, 54 and 41. Koalas score 23, 34 and 27 -avgDolhins= calcAverage(85, 54, 41) -avgKoalas= calcAverage(23, 34, 27) -console.log('dolAverage', avgDolhins, 'KoalaAverage', avgKoalas) +// avgDolhins= calcAverage(85, 54, 41) +// avgKoalas= calcAverage(23, 34, 27) +// console.log('dolAverage', avgDolhins, 'KoalaAverage', avgKoalas) -checkWinner(avgDolhins, avgKoalas) +// checkWinner(avgDolhins, avgKoalas) /////////////////////////////////////// @@ -68,40 +68,40 @@ HINT: Remember that an array needs a value in each position, and that value can GOOD LUCK 😀 */ -const calcTip = function (bill){ - if (bill >= 50 && bill <=300){ - return bill * 0.15 - } else{ - return bill * 0.20 - } -} +// const calcTip = function (bill){ +// if (bill >= 50 && bill <=300){ +// return bill * 0.15 +// } else{ +// return bill * 0.20 +// } +// } // arrow func && ternary // const calcTip = (bill) => bill >=50 && bill <=300 ? bill * 0.15 : bill * 0.20 -const bills = [125, 55, 44] -let tips = [ calcTip(bills[0]), calcTip(bills[1]), calcTip(bills[2])] +// const bills = [125, 55, 44] +// let tips = [ calcTip(bills[0]), calcTip(bills[1]), calcTip(bills[2])] -let total = [ bills[0]+ tips[0], bills[1] + tips[1], bills[2] + tips[2]] -console.log('tips arr', tips, 'total', total) +// let total = [ bills[0]+ tips[0], bills[1] + tips[1], bills[2] + tips[2]] +// console.log('tips arr', tips, 'total', total) // challenge video 43 - const jonas = { - firstName: 'Jonas', - lastName: 'Schmedtmann', - birthYear: 1991, - job: 'teacher', - friends: ['Michael', 'Peter', 'Steven'], - hasDriversLicense: false, - calcAge: function(){ - this.age = 2037 - this.birthYear - return this.age - }, - getSummary: function(){ - return `${this.firstName} is a ${this.calcAge()} y.o ${this.job} & he has ${this.hasDriversLicense? 'a ': 'no'}drivers license. ` - } -}; +// const jonas = { +// firstName: 'Jonas', +// lastName: 'Schmedtmann', +// birthYear: 1991, +// job: 'teacher', +// friends: ['Michael', 'Peter', 'Steven'], +// hasDriversLicense: false, +// calcAge: function(){ +// this.age = 2037 - this.birthYear +// return this.age +// }, +// getSummary: function(){ +// return `${this.firstName} is a ${this.calcAge()} y.o ${this.job} & he has ${this.hasDriversLicense? 'a ': 'no'}drivers license. ` +// } +// }; @@ -109,7 +109,7 @@ console.log('tips arr', tips, 'total', total) -console.log(jonas.getSummary()) +// console.log(jonas.getSummary()) /////////////////////////////////////// // Coding Challenge #3 @@ -126,29 +126,62 @@ TEST DATA: Marks weights 78 kg and is 1.69 m tall. John weights 92 kg and is 1.9 GOOD LUCK 😀 */ -const mark ={ - firstName: 'Mark', - lastName: 'Miller', - height: 1.69, - weight: 78, - calcBMI: function() { - this.bmi = Math.round(this.weight / this.height ** 2 ) - return this.bmi - } -} - -const john ={ - firstName: 'John', - lastName: 'Smith', - height: 1.95, - weight: 92, - calcBMI: function() { - this.bmi = Math.round(this.weight / this.height ** 2 ) - return this.bmi - } +// const mark ={ +// firstName: 'Mark', +// lastName: 'Miller', +// height: 1.69, +// weight: 78, +// calcBMI: function() { +// this.bmi = Math.round(this.weight / this.height ** 2 ) +// return this.bmi +// } +// } + +// const john ={ +// firstName: 'John', +// lastName: 'Smith', +// height: 1.95, +// weight: 92, +// calcBMI: function() { +// this.bmi = Math.round(this.weight / this.height ** 2 ) +// return this.bmi +// } +// } + +// mark.calcBMI(); +// john.calcBMI(); + +// console.log( mark.bmi > john.bmi ? `${mark.firstName} BMI: (${mark.bmi}) is higher than ${john.firstName}'s BMI: (${john.bmi})`: `${john.firstName}'s BMI ${john.bmi} is higher than ${mark.firstName} BMI (${mark.bmi})` ) + + +/////////////////////////////////////////////////////////////////// +// LECTURE: Introduction to Objects +// 1. Create an object called 'myCountry' for a country of your choice, containing +// properties 'country', 'capital', 'language', 'population' and +// 'neighbours' (an array like we used in previous assignments) + + +const myCountry ={ + country: 'argentina', + capital: 'buenos aires', + language: 'spanish', + population: 52, + neighnours:['uruguay', 'brasil', 'bolivia', 'chile'] } - -mark.calcBMI(); -john.calcBMI(); - -console.log( mark.bmi > john.bmi ? `${mark.firstName} BMI: (${mark.bmi}) is higher than ${john.firstName}'s BMI: (${john.bmi})`: `${john.firstName}'s BMI ${john.bmi} is higher than ${mark.firstName} BMI (${mark.bmi})` ) \ No newline at end of file +console.log(myCountry) +////////////////////////////////////////////////////////////////// +// LECTURE: Dot vs. Bracket Notation +// 1. Using the object from the previous assignment, log a string like this to the +// console: 'Finland has 6 million finnish-speaking people, 3 neighbouring countries +// and a capital called Helsinki.' +// 2. Increase the country's population by two million using dot notation, and then +// decrease it by two million using brackets notation. + +let str = `${myCountry['country']} has ${myCountry.population} million ${myCountry.language}-speaking people, ${myCountry.neighnours.length} neighboring countries and a capital called ${myCountry.capital}`; +console.log(str) + +myCountry.population= 54 +console.log(myCountry.population) + +myCountry['population']=52 +console.log(myCountry.population) From ebfec1bafb2e9b7eb99b7deffb6ca89960327322 Mon Sep 17 00:00:00 2001 From: Yanina Amatore Date: Thu, 12 Jan 2023 16:23:36 +1300 Subject: [PATCH 09/13] looping arrays --- 02-Fundamentals-Part-2/starter/script.js | 57 ++++++++++++++++++------ 1 file changed, 43 insertions(+), 14 deletions(-) diff --git a/02-Fundamentals-Part-2/starter/script.js b/02-Fundamentals-Part-2/starter/script.js index 75c43548a8..ac27aabe03 100755 --- a/02-Fundamentals-Part-2/starter/script.js +++ b/02-Fundamentals-Part-2/starter/script.js @@ -161,14 +161,20 @@ GOOD LUCK 😀 // 'neighbours' (an array like we used in previous assignments) -const myCountry ={ - country: 'argentina', - capital: 'buenos aires', - language: 'spanish', - population: 52, - neighnours:['uruguay', 'brasil', 'bolivia', 'chile'] -} -console.log(myCountry) +// const myCountry ={ +// country: 'argentina', +// capital: 'buenos aires', +// language: 'spanish', +// population: 52, +// neighnours:['uruguay', 'brasil', 'bolivia', 'chile'], +// describe: function(){ +// return `${this['country']} has ${this.population} million ${this.language}-speaking people, ${this.neighnours.length} neighboring countries and a capital called ${this.capital}` +// }, +// checkIsland: function(){ +// return this.neighnours.length >= 1 ? 'false' : 'true' +// } +// } +// console.log(myCountry) ////////////////////////////////////////////////////////////////// // LECTURE: Dot vs. Bracket Notation // 1. Using the object from the previous assignment, log a string like this to the @@ -177,11 +183,34 @@ console.log(myCountry) // 2. Increase the country's population by two million using dot notation, and then // decrease it by two million using brackets notation. -let str = `${myCountry['country']} has ${myCountry.population} million ${myCountry.language}-speaking people, ${myCountry.neighnours.length} neighboring countries and a capital called ${myCountry.capital}`; -console.log(str) +// let str = `${myCountry['country']} has ${myCountry.population} million ${myCountry.language}-speaking people, ${myCountry.neighnours.length} neighboring countries and a capital called ${myCountry.capital}`; +// console.log(str) + +// myCountry.population= 54 +// console.log(myCountry.population) + +// myCountry['population']=52 +// console.log(myCountry.population) -myCountry.population= 54 -console.log(myCountry.population) +// console.log(myCountry.describe()) +// console.log(myCountry.checkIsland()) + + +const jonasArray = [ + 'jonas', + 'Schmedtmann', + 20097-1991, + 'teacher', + ['michael', 'peter', 'steven'], + true +] + +let types = [] + +for(let i= 0 ; i < jonasArray.length ; i++) { + console.log(jonasArray[i], typeof jonasArray[i]) + + types[i] = typeof jonasArray[i] +} -myCountry['population']=52 -console.log(myCountry.population) +console.log(types) \ No newline at end of file From f307233b72b6cee2a9fdf6e2e8de4641450fbb72 Mon Sep 17 00:00:00 2001 From: Yanina Amatore Date: Fri, 13 Jan 2023 11:14:31 +1300 Subject: [PATCH 10/13] while loops --- 02-Fundamentals-Part-2/starter/script.js | 103 ++++++++++++++++++++--- 1 file changed, 89 insertions(+), 14 deletions(-) diff --git a/02-Fundamentals-Part-2/starter/script.js b/02-Fundamentals-Part-2/starter/script.js index ac27aabe03..7eb7d2454a 100755 --- a/02-Fundamentals-Part-2/starter/script.js +++ b/02-Fundamentals-Part-2/starter/script.js @@ -196,21 +196,96 @@ GOOD LUCK 😀 // console.log(myCountry.checkIsland()) -const jonasArray = [ - 'jonas', - 'Schmedtmann', - 20097-1991, - 'teacher', - ['michael', 'peter', 'steven'], - true -] +// const jonasArray = [ +// 'jonas', +// 'Schmedtmann', +// 2097-1991, +// 'teacher', +// ['michael', 'peter', 'steven'], +// true +// ] + +// let types = [] + +// for(let i= 0 ; i < jonasArray.length ; i++) { +// console.log(jonasArray[i], typeof jonasArray[i]) + + // types[i] = typeof jonasArray[i] +// types.push(typeof jonasArray[i]) +// } + +// console.log(types) + +// const years =[1991, 2007, 1969, 2020] + +// const ages=[] +// for ( let i=0 ; i Date: Fri, 13 Jan 2023 11:52:30 +1300 Subject: [PATCH 11/13] fundamentals completed --- 02-Fundamentals-Part-2/final/script.js | 1 + 02-Fundamentals-Part-2/starter/script.js | 37 +++++++++++++++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/02-Fundamentals-Part-2/final/script.js b/02-Fundamentals-Part-2/final/script.js index 8cee2087f7..6d8379dbdf 100755 --- a/02-Fundamentals-Part-2/final/script.js +++ b/02-Fundamentals-Part-2/final/script.js @@ -587,3 +587,4 @@ console.log(calcAverage([2, 3, 7])); console.log(calcAverage(totals)); console.log(calcAverage(tips)); */ + diff --git a/02-Fundamentals-Part-2/starter/script.js b/02-Fundamentals-Part-2/starter/script.js index 7eb7d2454a..788bc24725 100755 --- a/02-Fundamentals-Part-2/starter/script.js +++ b/02-Fundamentals-Part-2/starter/script.js @@ -288,4 +288,39 @@ HINT: Call calcTip in the loop and use the push method to add values to the tips 4.2. To calculate the average, divide the sum you calculated before by the length of the array (because that's the number of elements) 4.3. Call the function with the 'totals' array -GOOD LUCK 😀 \ No newline at end of file +GOOD LUCK 😀 +*/ + +let bills = [22, 295, 176, 440, 37, 105, 10, 1100, 86, 52] + +let tips = [] + +let totals = [] + +const calcTip = (bill) => bill >=50 && bill <=300 ? bill * 0.15 : bill * 0.20 + +for ( i=0 ; i < bills.length ; i++ ) { + + const tip =calcTip(bills[i]) + tips.push(tip) + totals.push(tip + bills[i]) +} + console.log('tips', tips, 'totals', totals) + + + + + +let calcAverage = (arr) =>{ +let sum = 0 + +for (let i=0 ; i Date: Fri, 13 Jan 2023 16:47:16 +1300 Subject: [PATCH 12/13] destructuring arr and obj --- .../starter/index.html | 1 + .../starter/script.js | 97 +++++++++++++++++++ 2 files changed, 98 insertions(+) diff --git a/09-Data-Structures-Operators/starter/index.html b/09-Data-Structures-Operators/starter/index.html index 7d248b95f5..63e6cfc5d8 100644 --- a/09-Data-Structures-Operators/starter/index.html +++ b/09-Data-Structures-Operators/starter/index.html @@ -1,4 +1,5 @@ +! diff --git a/09-Data-Structures-Operators/starter/script.js b/09-Data-Structures-Operators/starter/script.js index 2cc0fea5a0..904095fb8b 100644 --- a/09-Data-Structures-Operators/starter/script.js +++ b/09-Data-Structures-Operators/starter/script.js @@ -11,6 +11,16 @@ const restaurant = { categories: ['Italian', 'Pizzeria', 'Vegetarian', 'Organic'], starterMenu: ['Focaccia', 'Bruschetta', 'Garlic Bread', 'Caprese Salad'], mainMenu: ['Pizza', 'Pasta', 'Risotto'], + order: function (starterIndex, mainIndex) { + return [this.starterMenu[starterIndex], this.mainMenu[mainIndex]]; + }, + orderDelivery: function ({ + starterIndex=1, + mainIndex=0, + time=`20.00`, + address}){ + console.log(`Order Received! ${this.starterMenu[starterIndex]} and ${this.mainMenu[mainIndex]} will be delivered to ${address} at ${time}`); + }, openingHours: { thu: { @@ -27,3 +37,90 @@ const restaurant = { }, }, }; + +restaurant.orderDelivery( + { + time: `22.30`, + address: `96 BuckleyRoad`, + mainIndex:2, + starterIndex:2 + } +) + +restaurant.orderDelivery( + { + address: `96 BuckleyRoad`, + starterIndex:1 + } +) +const { name, openingHours, categories } = restaurant; +console.log(name, openingHours, categories); + +const { + name: restaurantName, + openingHours: hours, + categories: tags, +} = restaurant; +console.log(restaurantName, hours, tags); + +// default values +const { menu = [], starterMenu: starters = [] } = restaurant; +console.log(menu, starters); + +// mutating variables +let a = 111; +let b = 999; + +const obj = { a: 23, b: 7, c: 14 }; + +({ a, b } = obj); +console.log('a,b', a, b); + +// nested objects +const { + fri: { open:o, close:c }, +} = openingHours; +console.log(o, c); + + + +// Destructuring Arrays: +let [main, secondary] = restaurant.categories; +console.log(main, secondary); +[main, secondary] = [secondary, main]; +console.log(main, secondary) + +// --- a diff way: + +// let [main, secondary] = restaurant.categories; +// console.log(main, secondary); +// let temp = main; +// main = secondary; +// secondary = temp; +// console.log(main, secondary) + + + +const [starter, mainCourse] = restaurant.order(2, 0); +// console.log(starter, mainCourse) + +const nested = [2, 4, [5, 6]]; + +// const [i, , j] = nested + +const [i, , [j, k]] = nested; +// console.log(i, j, k) + +const [p = 1, q = 2, r = 3] = ['marce', 'sos']; +// console.log(p, q, r) + +// console.log(student1) +// console.log(student2) + +// let [student1, student2] = ['budi', 'sinta'] +let student1 = 'budi'; +let student2 = 'sinta'; +[student1, student2] = [student2, student1]; + +// console.log('student1', student1); // 'sinta' +// console.log('student2', student2); // 'budi' From 4253de7d662b71b22b9fdc7c3a0968bf3500289a Mon Sep 17 00:00:00 2001 From: Yanina Amatore Date: Wed, 25 Jan 2023 15:07:16 +1300 Subject: [PATCH 13/13] rest operator class --- .../starter/script.js | 75 ++++++++++++------- 1 file changed, 47 insertions(+), 28 deletions(-) diff --git a/09-Data-Structures-Operators/starter/script.js b/09-Data-Structures-Operators/starter/script.js index 904095fb8b..398306cbad 100644 --- a/09-Data-Structures-Operators/starter/script.js +++ b/09-Data-Structures-Operators/starter/script.js @@ -15,13 +15,20 @@ const restaurant = { return [this.starterMenu[starterIndex], this.mainMenu[mainIndex]]; }, orderDelivery: function ({ - starterIndex=1, - mainIndex=0, - time=`20.00`, - address}){ - console.log(`Order Received! ${this.starterMenu[starterIndex]} and ${this.mainMenu[mainIndex]} will be delivered to ${address} at ${time}`); + starterIndex = 1, + mainIndex = 0, + time = `20.00`, + address, + }) { + console.log( + `Order Received! ${this.starterMenu[starterIndex]} and ${this.mainMenu[mainIndex]} will be delivered to ${address} at ${time}` + ); + }, + orderPasta: function (ing1, ing2,ing3) { + console.log( + `Order Received! Preparing pasta with ${ing1},${ing2} & ${ing3}` + ); }, - openingHours: { thu: { open: 12, @@ -38,21 +45,17 @@ const restaurant = { }, }; -restaurant.orderDelivery( - { - time: `22.30`, - address: `96 BuckleyRoad`, - mainIndex:2, - starterIndex:2 - } -) - -restaurant.orderDelivery( - { - address: `96 BuckleyRoad`, - starterIndex:1 - } -) +restaurant.orderDelivery({ + time: `22.30`, + address: `96 BuckleyRoad`, + mainIndex: 2, + starterIndex: 2, +}); + +restaurant.orderDelivery({ + address: `96 BuckleyRoad`, + starterIndex: 1, +}); const { name, openingHours, categories } = restaurant; console.log(name, openingHours, categories); @@ -78,17 +81,15 @@ console.log('a,b', a, b); // nested objects const { - fri: { open:o, close:c }, + fri: { open: o, close: c }, } = openingHours; console.log(o, c); - - -// Destructuring Arrays: +// Destructuring Arrays: let [main, secondary] = restaurant.categories; console.log(main, secondary); [main, secondary] = [secondary, main]; -console.log(main, secondary) +console.log(main, secondary); // --- a diff way: @@ -99,8 +100,6 @@ console.log(main, secondary) // secondary = temp; // console.log(main, secondary) - - const [starter, mainCourse] = restaurant.order(2, 0); // console.log(starter, mainCourse) @@ -124,3 +123,23 @@ let student2 = 'sinta'; // console.log('student1', student1); // 'sinta' // console.log('student2', student2); // 'budi' + +const newMenu = [...restaurant.starterMenu, ...restaurant.mainMenu]; + +// console.log(newMenu) + +const restaurantCopy = { ...restaurant }; +// console.log(restaurantCopy) +restaurantCopy.name = 'la Bella Pasta'; + +// console.log(restaurantCopy.name) +// console.log(restaurant.name) + +// const ingredients = [ +// prompt('1st Pasta ingredient'), +// prompt('2nd Pasta ingredient'), +// prompt('3rd Pasta ingredient'), +// ]; +// console.log(ingredients); + +// restaurant.orderPasta(...ingredients);