Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions question-1.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,14 @@ 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);
console.log("To-do id: 4, Go to the gym")


20 changes: 20 additions & 0 deletions question-2.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,23 @@ const inventory = [
{ name: "Banana", price: 10, quantity: 50 },
];
// เริ่มเขียนโค้ดตรงนี้
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
console.log(applePrice);
console.log(bananaPrice);
console.log(orangePrice);
let totalSum = applePrice + bananaPrice + orangePrice
*/
console.log(`มูลค่ารวมของจำนวนสินค้าทั้งหมดในสต็อก ${totalSum} บาท`);

15 changes: 15 additions & 0 deletions question-3.js
Original file line number Diff line number Diff line change
@@ -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"))
22 changes: 21 additions & 1 deletion question-4.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,27 @@
// 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.length;i++){
console.log(inventory[i].quantity)
if(inventory[i].quantity < minPrice){
minPrice = inventory[i].quantity
namelowest = inventory[i].name
}

}

console.log(`สินค้าที่มีจำนวนต่ำที่สุดในคลังสินค้าคือ ${namelowest} ซึ่งมี ${minPrice} บาท`);

/*if(minPrice >= inventory[i].price){
console.log(inventory[i].price)
console.log(inventory[i].quantity)
}*/

// return minPrice = inventory.price[i]
94 changes: 94 additions & 0 deletions question-5.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,98 @@ 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 === "เสื้อยืด"){
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"))