From 4cc031b68d4f3ac094224964b6c7c2029110f94d Mon Sep 17 00:00:00 2001 From: "github-classroom[bot]" <66690702+github-classroom[bot]@users.noreply.github.com> Date: Wed, 22 May 2024 06:04:04 +0000 Subject: [PATCH 1/4] Setting up GitHub Classroom Feedback From 8e9b8ce000e153666d0bd531e971e18ef7f2a2e2 Mon Sep 17 00:00:00 2001 From: Hunter Date: Wed, 22 May 2024 15:13:43 +0700 Subject: [PATCH 2/4] hunter/checkpoint-1 --- question-1.js | 9 +++++++++ question-2.js | 11 ++++++++++ question-3.js | 15 ++++++++++++++ question-4.js | 18 +++++++++++++++++ question-5.js | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 109 insertions(+) diff --git a/question-1.js b/question-1.js index 41bc46c..983cab4 100644 --- a/question-1.js +++ b/question-1.js @@ -6,3 +6,12 @@ const myTodo = [ { id: 4, todo: "Wash dishes" }, ]; // เริ่มเขียนโค้ดตรงนี้ + +//myTodo[3] = {id: 4, todo: "go gym"} +//myTodo.pop() +myTodo[3] = { id: 4, todo: "Go to the gym" } +myTodo.push({ id: 5, todo: "Walk the dog" }) +myTodo.pop() +console.log(myTodo[3]) + + diff --git a/question-2.js b/question-2.js index 0515a8b..350b8b4 100644 --- a/question-2.js +++ b/question-2.js @@ -4,3 +4,14 @@ const inventory = [ { name: "Banana", price: 10, quantity: 50 }, ]; // เริ่มเขียนโค้ดตรงนี้ +inventory[0].quantity = 200 +inventory.push({ name: "Orange", price: 20, quantity: 300 }) +let applePrice = inventory[0].price * inventory[0].quantity +let bananaPrice = inventory[1].price * inventory[1].quantity +let orangePrice = inventory[2].price * inventory[2].quantity +console.log(applePrice); +console.log(bananaPrice); +console.log(orangePrice); +let totalSum = applePrice+ bananaPrice+ orangePrice + +console.log(`มูลค่ารวมของจำนวนสินค้าทั้งหมดในสต็อก ${totalSum} บาท`); \ No newline at end of file diff --git a/question-3.js b/question-3.js index 8a49bb4..4ab529f 100644 --- a/question-3.js +++ b/question-3.js @@ -1,3 +1,18 @@ // Question #3 let userPassword = ""; // เริ่มเขียนโค้ดตรงนี้ +function checkPasswordStrength(userPassword){ + if(userPassword.length < 6){ + return "Weak" + }else if(userPassword.length >=6 && userPassword.length < 10){ + return "Medium" + }else if(userPassword.length >= 10) { + return "Strong" + } +} + + + +console.log(checkPasswordStrength("swnalWadqQ")) +console.log(checkPasswordStrength("TechUp")) +console.log(checkPasswordStrength("abcde")) \ No newline at end of file diff --git a/question-4.js b/question-4.js index 2dc5a21..b5a94e0 100644 --- a/question-4.js +++ b/question-4.js @@ -5,3 +5,21 @@ const inventory = [ { name: "Orange", price: 30, quantity: 60 }, ]; // เริ่มเขียนโค้ดตรงนี้ +let minPrice = Infinity; + +for (let i=0;i= inventory[i].price){ + console.log(inventory[i].price) + console.log(inventory[i].quantity) +}*/ + +// return minPrice = inventory.price[i] \ No newline at end of file diff --git a/question-5.js b/question-5.js index e0d1c4c..1c5494d 100644 --- a/question-5.js +++ b/question-5.js @@ -19,3 +19,59 @@ const products = [ const promotionCode = ""; // เริ่มเขียนโค้ดตรงนี้ +function calculateTotalPrice(product,promotionCode){ + if(promotionCode === "SALE20"){ + if(product === "เสื้อยืด"){ + return (products[0].price*products[0].quantity)-(products[0].price*products[0].quantity)*0.2 + }else if(product === "กางเกงยีนส์"){ + return (products[1].price*products[1].quantity)-(products[1].price*products[1].quantity)*0.2 + }else if(product === "เสื้อเชิ้ต"){ + return (products[2].price*products[2].quantity)-(products[2].price*products[2].quantity)*0.2 + } + + }else if(promotionCode === "SALE50"){ + if(product === "เสื้อยืด"){ + return (products[0].price*products[0].quantity)-(products[0].price*products[0].quantity)*0.5 + }else if(product === "กางเกงยีนส์"){ + return (products[1].price*products[1].quantity)-(products[1].price*products[1].quantity)*0.5 + }else if(product === "เสื้อเชิ้ต"){ + return (products[2].price*products[2].quantity)-(products[2].price*products[2].quantity)*0.5 + } + }else if(promotionCode.includes("")){ + if(product === "เสื้อยืด"){ + return (products[0].price*products[0].quantity) + }else if(product === "กางเกงยีนส์"){ + return (products[1].price*products[1].quantity) + }else if(product === "เสื้อเชิ้ต"){ + return (products[2].price*products[2].quantity) + } + } +} + +console.log(calculateTotalPrice("เสื้อยืด","SALE20")); +console.log(calculateTotalPrice("เสื้อยืด","SALE50")); +console.log(calculateTotalPrice("เสื้อยืด","")); +console.log(calculateTotalPrice("เสื้อเชิ้ต","SALE20")); +console.log(calculateTotalPrice("เสื้อเชิ้ต","SALE50")); +console.log(calculateTotalPrice("เสื้อเชิ้ต","")); +console.log(calculateTotalPrice("กางเกงยีนส์","SALE20")); +console.log(calculateTotalPrice("กางเกงยีนส์","SALE50")); +console.log(calculateTotalPrice("กางเกงยีนส์","")); + + + + + +/* +console.log((products[0].price * products[0].quantity)*0.2) +function calculateTotalPrice(products,promotionCode){ + console.log((products.price * products.quantity)*0.2) + if(promotionCode === "SALE20"){ + if(products === "เสื้อยืด"){ + console.log(products.price * products.quantity) + promotionCode.inculdes("") + } + } +} +*/ +console.log(calculateTotalPrice("เสื้อยืด","SALE20")) \ No newline at end of file From 78e261c5c6c86c023176a59d363dc1578bed7aba Mon Sep 17 00:00:00 2001 From: Hunter Date: Sat, 25 May 2024 17:32:09 +0700 Subject: [PATCH 3/4] hunter/solved-again --- question-1.js | 4 +++- question-2.js | 5 +++-- question-4.js | 6 ++++-- question-5.js | 44 +++++++++++++++++++++++++++++++++++++++++--- 4 files changed, 51 insertions(+), 8 deletions(-) diff --git a/question-1.js b/question-1.js index 983cab4..6d413f8 100644 --- a/question-1.js +++ b/question-1.js @@ -12,6 +12,8 @@ const myTodo = [ myTodo[3] = { id: 4, todo: "Go to the gym" } myTodo.push({ id: 5, todo: "Walk the dog" }) myTodo.pop() -console.log(myTodo[3]) + +console.log(myTodo); +console.log("To-do id: 4, Go to the gym") diff --git a/question-2.js b/question-2.js index 350b8b4..4affc69 100644 --- a/question-2.js +++ b/question-2.js @@ -12,6 +12,7 @@ let orangePrice = inventory[2].price * inventory[2].quantity console.log(applePrice); console.log(bananaPrice); console.log(orangePrice); -let totalSum = applePrice+ bananaPrice+ orangePrice +let totalSum = applePrice + bananaPrice + orangePrice + +console.log(`มูลค่ารวมของจำนวนสินค้าทั้งหมดในสต็อก ${totalSum} บาท`); -console.log(`มูลค่ารวมของจำนวนสินค้าทั้งหมดในสต็อก ${totalSum} บาท`); \ No newline at end of file diff --git a/question-4.js b/question-4.js index b5a94e0..ce13e48 100644 --- a/question-4.js +++ b/question-4.js @@ -1,21 +1,23 @@ // Question #4 const inventory = [ { name: "Apple", price: 35, quantity: 100 }, - { name: "Banana", price: 10, quantity: 50 }, + { name: "Banana", price: 10, quantity: 40 }, { name: "Orange", price: 30, quantity: 60 }, ]; // เริ่มเขียนโค้ดตรงนี้ let minPrice = Infinity; +let namelowest = "" for (let i=0;i= inventory[i].price){ console.log(inventory[i].price) diff --git a/question-5.js b/question-5.js index 1c5494d..780d23c 100644 --- a/question-5.js +++ b/question-5.js @@ -18,7 +18,46 @@ const products = [ ]; const promotionCode = ""; + +function calculateTotalPrice(products, promotionCode) { + let totalPrice = 0; + for (let i = 0; i < products.length; i++) { + price = products[i].price * products[i].quantity; + console.log(price); + totalPrice = totalPrice + price; + console.log(totalPrice); + } + + if (promotionCode === "SALE20") { + return totalPrice * 0.8; + } else if (promotionCode === "SALE50") { + return totalPrice * 0.5; + } else { + return totalPrice * 1; + } +} +console.log(calculateTotalPrice(products, "")); +console.log(calculateTotalPrice(products,"SALE20")); +console.log(calculateTotalPrice(products,"SALE50")); + + + +/* +function code(acc,curr){ + console.log(acc); + console.log(curr); + return (acc+curr.) +} + +console.log(code); + +let result = products.reduce(code) +console.log(result) + +*/ + // เริ่มเขียนโค้ดตรงนี้ +/* function calculateTotalPrice(product,promotionCode){ if(promotionCode === "SALE20"){ if(product === "เสื้อยืด"){ @@ -59,8 +98,7 @@ console.log(calculateTotalPrice("กางเกงยีนส์","SALE50")); console.log(calculateTotalPrice("กางเกงยีนส์","")); - - +*/ /* console.log((products[0].price * products[0].quantity)*0.2) @@ -74,4 +112,4 @@ function calculateTotalPrice(products,promotionCode){ } } */ -console.log(calculateTotalPrice("เสื้อยืด","SALE20")) \ No newline at end of file +//console.log(calculateTotalPrice("เสื้อยืด","SALE20")) From 5edefdf4ee1aa059b9432955e43cf7366b877e31 Mon Sep 17 00:00:00 2001 From: Hunter Date: Sun, 26 May 2024 00:04:38 +0700 Subject: [PATCH 4/4] hunter/solved-q.2 --- question-2.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/question-2.js b/question-2.js index 4affc69..4d8ca7a 100644 --- a/question-2.js +++ b/question-2.js @@ -6,6 +6,14 @@ const inventory = [ // เริ่มเขียนโค้ดตรงนี้ inventory[0].quantity = 200 inventory.push({ name: "Orange", price: 20, quantity: 300 }) + +const totalSum = inventory.reduce((acc,curr)=>{ + console.log(acc); + console.log(curr); + return acc+(curr.price*curr.quantity) +},0) +console.log(totalSum); +/* let applePrice = inventory[0].price * inventory[0].quantity let bananaPrice = inventory[1].price * inventory[1].quantity let orangePrice = inventory[2].price * inventory[2].quantity @@ -13,6 +21,6 @@ console.log(applePrice); console.log(bananaPrice); console.log(orangePrice); let totalSum = applePrice + bananaPrice + orangePrice - +*/ console.log(`มูลค่ารวมของจำนวนสินค้าทั้งหมดในสต็อก ${totalSum} บาท`);