# 🏅 3/5(五) 每日任務 ###### tags: `JS 直播班 - 2021 春季班` 問題 --- 請依照註解的要求完成這段程式碼: ```js= let ProductInfo = { Price: 1000, // 購買價格 coupons:[ { due_date: "2021-10-15", id: 123, is_enabled: 0, percent: 0.7, title: "特惠七折", }, { due_date: "2021-08-08", id: 456, is_enabled: 1, percent: 0.5, // 折扣比例 title: "特惠五折", } ] } /* 請取得 coupons 陣列中 id 為 456 的 percent,並賦值給 discountPercent */ let discountPercent; /* 請取得 coupons 陣列中 id 為 456 的 title,並賦值給 title */ let title; /* 請取得 coupons 陣列中 id 為 456 的 is_enabled,並填入以下 if 判斷式中; 如果判斷為 true,則對「購買價格」進行折扣*/ if(/* 程式碼撰寫處 */){ /* 程式碼撰寫處,對「購買價格」進行折扣*/ console.log(`優惠券已啟用,${title}`); }else { console.log("優惠券未啟用"); } console.log(`購買價格 ${ProductInfo.Price}`); ``` 回報流程 --- 將答案寫在 CodePen 並複製 CodePen 連結貼至 thread 中回報就算完成了喔! 解答請參考下圖(需打開程式碼的部分觀看) ![](https://i.imgur.com/6UoJVtD.png) <!-- 解答 let ProductInfo = { Price: 1000, coupons:[ { due_date: "2021-10-15", id: 123, is_enabled: 0, percent: 0.7, title: "特惠七折", }, { due_date: "2021-08-08", id: 456, is_enabled: 1, percent: 0.5, title: "特惠五折", } ] } let discountPercent = ProductInfo.coupons[1].percent; let title = ProductInfo.coupons[1].title; if(ProductInfo.coupons[1].is_enabled){ ProductInfo.Price *= discountPercent; console.log(`優惠券已啟用,${title}`); }else { console.log("優惠券未啟用"); } console.log(`購買價格 ${ProductInfo.Price}`); -->