Interactive Section - Arrays & Objects
လေ့ကျင့်ခန်း ၁ (Exercise 1): Shopping List 🛒
Section titled “လေ့ကျင့်ခန်း ၁ (Exercise 1): Shopping List 🛒”၁။ shoppingList လို့ အမည်ပေးထားတဲ့ Array တစ်ခုကို တည်ဆောက်ပါ။ အဲ့ဒီအထဲမှာ “Milk”, “Bread”, “Eggs” ဆိုတဲ့ Items သုံးခု ထည့်ထားပါ။
၂။ အဲ့ဒီ Array ရဲ့ အနောက်ဆုံး နေရာကို “Coffee” ထပ်ထည့်ပါ။ (push ကို အသုံးပြုပါ)
၃။ အရှေ့ဆုံး နေရာမှာ ရှိနေတဲ့ “Milk” ကို ဖျက်ထုတ်လိုက်ပါ။ (shift ကို အသုံးပြုပါ)
၄။ နောက်ဆုံး ကျန်ရှိနေတဲ့ List ကို console.log() အသုံးပြုပြီး ထုတ်ကြည့်ပါ။
let shoppingList = ["Milk", "Bread", "Eggs"];// သင်၏ Code များကို ဤနေရာတွင် ဆက်လက် ရေးသားပါ...လေ့ကျင့်ခန်း ၂ (Exercise 2): User Profile 👤
Section titled “လေ့ကျင့်ခန်း ၂ (Exercise 2): User Profile 👤”၁။ user ဆိုတဲ့ Object တစ်ခု တည်ဆောက်ပါ။ (အထဲမှာ name, age, email ဆိုတဲ့ Properties တွေ ပါဝင်ပါစေ)
၂။ အဲ့ဒီ user Object ထဲက age တန်ဖိုးကို (၁) ထပ်ပေါင်းပြီး တိုးလိုက်ပါ။
၃။ user Object ထဲကို location ဆိုတဲ့ Property အသစ်တစ်ခု ထပ်ထည့်ပါ။ (တန်ဖိုးကို “Yangon” လို့ သတ်မှတ်ပါ)
let user = { name: "Su Su", age: 24, email: "susu@example.com"};// သင်၏ Code များကို ဤနေရာတွင် ဆက်လက် ရေးသားပါ...အထူးစိန်ခေါ်မှု (Challenge): Total Price Calculator 💰
Section titled “အထူးစိန်ခေါ်မှု (Challenge): Total Price Calculator 💰”အောက်မှာ ပေးထားတဲ့ cart Array ထဲက ကုန်ပစ္စည်း တစ်ခုချင်းစီရဲ့ ဈေးနှုန်း (price) တွေကို Loop အသုံးပြုပြီး စုစုပေါင်း ကျသင့်ငွေ (Total Price) တွက်ချက်ပေးပါ။
let cart = [ { item: "Book", price: 10 }, { item: "Pen", price: 2 }, { item: "Notebook", price: 5 }];
let total = 0;
// ဒီနေရာတွင် Array ကို Loop ပတ်ပြီး price များကို total ထဲသို့ ပေါင်းထည့်သည့် Code ရေးပါ
console.log("Total Price:", total); // ရလဒ် 17 ထွက်ရပါမည်