The web development ecosystem includes hundreds of specialized tools that help developers build, test, and maintain applications efficiently. Your task is to research and understand tools that complement the ones covered in this lesson.
**字數要求:**
- 每個解釋應為 2-3 句。
**Your Mission:** Select **three tools** that are **not covered in this lesson** (avoid choosing code editors, browsers, or command line tools already listed). Focus on tools that solve specific problems in modern web development workflows.
**Workflow Integration:** [1 sentence about how it fits into development process]
```
## Quality Guidelines
- **Choose current tools**: Select tools that are actively maintained and widely used in 2025
- **Focus on value**: Explain the specific benefits, not just what the tool does
- **Professional context**: Consider tools used by development teams, not just individual hobbyists
- **Diverse selection**: Pick tools from different categories to show breadth of the ecosystem
- **Modern relevance**: Prioritize tools that align with current web development trends and best practices
## Rubric
| Excellent | Good | Needs Improvement |
|-----------|------|-------------------|
| **Clearly explained why developers use each tool and what problems it solves** | **Explained what the tool does but missed some context about its value** | **Listed tools but didn't explain their purpose or benefits** |
| **Provided official documentation links for all tools** | **Provided mostly official links with 1-2 tutorial sites** | **Relied mainly on tutorial sites rather than official documentation** |
| **Selected current, professionally-used tools from diverse categories** | **Selected good tools but limited variety in categories** | **Selected outdated tools or only from one category** |
| **Demonstrated understanding of how tools fit into development workflows** | **Showed some understanding of professional context** | **Focused only on tool features without workflow context** |
> 💡 **Research Tip**: Look for tools mentioned in job postings for web developers, check popular developer surveys, or explore the dependencies used by successful open-source projects on GitHub!
---
<!-- CO-OP TRANSLATOR DISCLAIMER START -->
**免責聲明**:
本文件已使用 AI 翻譯服務 [Co-op Translator](https://github.com/Azure/co-op-translator) 進行翻譯。儘管我們致力於提供準確的翻譯,請注意自動翻譯可能包含錯誤或不準確之處。原始文件的母語版本應被視為權威來源。對於重要資訊,建議使用專業人工翻譯。我們對因使用此翻譯而引起的任何誤解或錯誤解釋概不負責。
本文件使用 AI 翻譯服務 [Co-op Translator](https://github.com/Azure/co-op-translator) 進行翻譯。雖然我們力求準確,但請注意,自動翻譯可能包含錯誤或不準確之處。原始文件的本地語言版本應被視為權威來源。對於重要資訊,建議使用專業人工翻譯。我們對因使用本翻譯而引起的任何誤解或誤讀概不負責。
Imagine you are building a modern e-commerce shopping cart system. This assignment will help you understand how different JavaScript data types work together to create real-world applications.
Create a comprehensive analysis of how you would use JavaScript data types in a shopping cart application. For each of the seven primitive data types and objects, you need to:
1. **Identify** the data type and its purpose
2. **Explain** why this data type is the best choice for specific shopping cart features
3. **Provide** realistic code examples showing the data type in action
4. **Describe** how this data type interacts with other parts of the shopping cart
### Required Data Types to Cover
**Primitive Data Types:**
- **String**: Product names, descriptions, user information
| **Data Type Coverage** | All 7 primitive types and objects/arrays covered with detailed explanations | 6-7 data types covered with good explanations | 4-5 data types covered with basic explanations | Fewer than 4 data types or minimal explanations |
| **Code Examples** | All examples are realistic, working, and well-commented | Most examples work and are relevant to e-commerce | Some examples work but may be generic | Code examples are incomplete or non-functional |
| **Real-world Application** | Clearly connects each data type to practical shopping cart features | Good connection to e-commerce scenarios | Some connection to shopping cart context | Limited real-world application demonstrated |
| **Technical Accuracy** | All technical information is correct and demonstrates deep understanding | Most technical information is accurate | Generally accurate with minor errors | Contains significant technical errors |
| **Communication** | Explanations are clear, beginner-friendly, and well-organized | Good explanations that are mostly clear | Explanations are understandable but may lack clarity | Explanations are unclear or poorly organized |
| **Bonus Elements** | Includes multiple bonus challenges with excellent execution | Includes one or more bonus challenges well done | Attempts bonus challenges with mixed success | No bonus challenges attempted |
### Learning Objectives
By completing this assignment, you will:
- ✅ **Understand** the seven JavaScript primitive data types and their uses
- ✅ **Apply** data types to real-world programming scenarios
- ✅ **Analyze** when to choose specific data types for different purposes
- ✅ **Create** working code examples that demonstrate data type usage
- ✅ **Explain** technical concepts in beginner-friendly language
- ✅ **Connect** fundamental programming concepts to practical applications
---
<!-- CO-OP TRANSLATOR DISCLAIMER START -->
**免責聲明**:
本文件已使用 AI 翻譯服務 [Co-op Translator](https://github.com/Azure/co-op-translator) 進行翻譯。雖然我們致力於提供準確的翻譯,但請注意,自動翻譯可能包含錯誤或不準確之處。原始文件的母語版本應被視為權威來源。對於重要資訊,建議使用專業人工翻譯。我們對因使用此翻譯而引起的任何誤解或錯誤解釋概不負責。
本文件由 AI 翻譯服務 [Co-op Translator](https://github.com/Azure/co-op-translator) 翻譯而成。雖然我們力求準確,但請注意自動翻譯可能包含錯誤或不準確之處。原始文件的母語版本應被視為權威來源。如涉及重要資訊,建議使用專業人工翻譯。本公司不就使用此翻譯而產生的任何誤解或誤譯承擔責任。
while (userInput !== "quit" && attempts <maxAttempts){
userInput = prompt(`Enter 'quit' to exit (attempt ${attempts + 1}):`);
attempts++;
}
if (attempts >= maxAttempts) {
console.log("Maximum attempts reached!");
}
```
✅ 為什麼你會選擇使用 for 迴圈而不是 while 迴圈?17K 名觀眾在 StackOverflow 上有同樣的疑問,一些意見可能 [對你有趣](https://stackoverflow.com/questions/39969145/while-loops-vs-for-loops-in-javascript)。
✅ 你為什麼會選擇 for 迴圈還是 while 迴圈?在 StackOverflow 上有 1.7 萬人討論這問題,裡面的一些意見[可能讓你感興趣](https://stackoverflow.com/questions/39969145/while-loops-vs-for-loops-in-javascript)。
除了 for 和 while 迴圈之外,還有其他方法可以迭代陣列,例如 [forEach](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach)、[for-of](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/for...of) 和 [map](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array/map)。使用其中一種技術重寫你的陣列迴圈。
在這節課中,我們將使用 HTML 來設計虛擬玻璃缸介面的「骨架」。它將包含一個標題和三個欄位:左右兩側的欄位放置可拖動的植物,中間的區域則是實際的玻璃缸。到本課結束時,你將能看到欄位中的植物,但介面可能會看起來有點奇怪;別擔心,在下一節課中,我們會用 CSS 來美化介面。
在深入 HTML 程式碼之前,讓我們先為你的玻璃花房專案建立一個適當的工作空間。從一開始就建立有條理的檔案結構,是個非常重要的習慣,對你的整個網頁開發旅程都會有幫助。
### 任務
### 任務:建立你的專案結構
在你的電腦上,建立一個名為「terrarium」的資料夾,並在裡面新增一個名為「index.html」的檔案。你可以在 Visual Studio Code 中完成這個操作:打開一個新的 VS Code 視窗,點擊「開啟資料夾」,然後導航到你新建的資料夾。接著,在 Explorer 面板中點擊小的「檔案」按鈕,創建新檔案:
> 🎥 **現場示範**:觀看[螢幕閱讀器如何與網頁互動](https://www.youtube.com/watch?v=OUDV1gqs9GA)以理解語義化標記對無障礙的重要性。注意正確的 HTML 結構如何幫助使用者有效導航。
介面的最後一部分涉及創建將被樣式化為玻璃缸的標記。
## 建立玻璃花房容器
### 任務:
現在讓我們新增玻璃花房本身的 HTML 結構——那個將用來放置植物的玻璃容器。這部分示範一個重要概念:HTML 提供結構,但沒有 CSS 樣式,這些元素暫時不會可見。
在最後一個 `</div>` 標籤上方新增以下標記:
玻璃花房標記使用描述性的 class 名稱,方便下一課的 CSS 樣式設計既直覺又易維護。
### 任務:新增玻璃花房結構
將此標記插入在最後一個 `</div>` 標籤之前(即頁面容器關閉標籤前):
```html
<divid="terrarium">
@ -221,29 +395,200 @@ HTML 文件的「head」區域包含有關網頁的重要資訊,也稱為[元
</div>
```
✅ 即使你新增了這些標記到螢幕上,你仍然看不到任何渲染。為什麼?
**了解這個玻璃花房結構的含義:**
- **建立** 一個主要的玻璃花房容器,並附加獨特 ID 以便樣式設計
- **定義**每個視覺組件的獨立元素(頂部、牆壁、土壤、底部)
- **包含**用於玻璃反射效果(光澤元素)的嵌套元素
- **使用**清晰指出每個元素用途的描述性類名
- **準備**結構以便 CSS 造出玻璃植物箱的外觀
> 🤔 **注意到了嗎?**:即使你已加入這些標記,頁面上卻看不到任何新東西!這正好說明了 HTML 提供結構,而 CSS 提供外觀。這些 `<div>` 元素存在,但還沒有視覺樣式——下一課會教你如何加上!
```mermaid
flowchart TD
A[HTML 文件] --> B[文件頭]
A --> C[文件主體]
B --> D[標題元素]
B --> E[Meta 字符集]
B --> F[Meta 視窗設定]
C --> G[主標題]
C --> H[頁面容器]
H --> I[左邊容器帶 7 株植物]
H --> J[右邊容器帶 7 株植物]
H --> K[生態瓶結構]
style A fill:#e1f5fe
style B fill:#fff3e0
style C fill:#e8f5e8
style H fill:#f3e5f5
```
### 🔄 **教學檢視**
**掌握 HTML 結構**:在繼續進行前,請確保你能:
- ✅ 解釋 HTML 結構與視覺外觀的差異
- ✅ 識別語意與非語意的 HTML 元素
- ✅ 描述正確標記如何提升無障礙使用
- ✅ 認識完整文件樹狀結構
**測試你的理解**:嘗試在瀏覽器中禁用 JavaScript 並移除 CSS,開啟你的 HTML 檔案。這能讓你看到純粹的語意結構。
---
## 🚀挑戰
## GitHub Copilot Agent 挑戰
使用 Agent 模式完成以下挑戰:
**描述:** 創建一個語意化的 HTML 結構,用於可加入植物箱專案的植物護理指南部分。
**提示:** 建立一個語意化 HTML 區塊,包含主標題「Plant Care Guide」及三個子區塊,標題分別是「Watering」、「Light Requirements」和「Soil Care」,每個子區塊包含一段植物護理資訊。使用適當的語意 HTML 標籤如 `<section>`、`<h2>`、`<h3>` 和 `<p>`,妥善組織內容。
要完成課後測驗,請參考此學習模組:[使用 CSS 為 HTML 應用程式設計樣式](https://docs.microsoft.com/learn/modules/build-simple-website/4-css-basics/?WT.mc_id=academic-77807-sagibbon)
欲獲得完整 CSS 基礎教學,完成這個 Microsoft Learn 課程:[使用 CSS 美化你的 HTML 應用程式](https://docs.microsoft.com/learn/modules/build-simple-website/4-css-basics/?WT.mc_id=academic-77807-sagibbon)
歡迎來到網頁開發中最吸引人的部分之一——讓事物互動起來!文件物件模型(DOM)就像你的 HTML 與 JavaScript 之間的橋樑,今天我們將利用它讓你的植物箱活起來。當 Tim Berners-Lee 發明第一台網頁瀏覽器時,他就想像了一個文件可以動態且互動的網路,而 DOM 讓這個願景成為可能。
> DOM 與對應 HTML 標記的示意圖。來自 [Olfa Nasraoui](https://www.researchgate.net/publication/221417012_Profile-Based_Focused_Crawler_for_Social_Media-Sharing_Websites)
> DOM 與對應 HTML 標記的示意圖。來自 [Olfa Nasraoui](https://www.researchgate.net/publication/221417012_Profile-Based_Focused_Crawler_for_Social_Media-Sharing_Websites)
> DOM 與其對應的 HTML 標記的表示圖。來源:[Olfa Nasraoui](https://www.researchgate.net/publication/221417012_Profile-Based_Focused_Crawler_for_Social_Media-Sharing_Websites)
> 注意:在將外部 JavaScript 文件引入 HTML 文件時,使用 `defer` 屬性,這樣可以確保 JavaScript 在 HTML 文件完全加載後才執行。你也可以使用 `async` 屬性,允許腳本在 HTML 文件解析時執行,但在我們的情況下,確保 HTML 元素完全可用以進行拖拽操作更為重要。
---
在讓元素可拖放前,JavaScript 需要找到它們,在 DOM 中定位它們。可以把這看成圖書館的目錄系統——只要有目錄號碼,你就能準確找到想要的書。
## DOM 元素
我們會使用 `document.getElementById()` 來建立這連結。這就像有一個精確的檔案系統——你給出 ID,它就能找到你 HTML 中的正確元素。
首先,你需要在 DOM 中創建對要操作的元素的引用。在我們的例子中,這些元素是目前位於側邊欄的 14 個植物。
這裡發生了什麼?你正在引用文件,並在其 DOM 中查找具有特定 Id 的元素。還記得我們在 HTML 課程中為每個植物圖片分配了唯一的 Id(例如 `id="plant1"`)嗎?現在你可以利用這些 Id。識別每個元素後,你將該元素傳遞給一個名為 `dragElement` 的函數(稍後會構建該函數)。因此,HTML 中的元素現在已啟用拖拽功能,或者即將啟用。
**這段程式碼完成了什麼:**
- **定位** 每個植物元素於 DOM 中,根據其獨特的 ID
- **取得** JavaScript 對應的 HTML 元素參考
- **將** 每個元素傳遞給 `dragElement` 函數(接下來我們會寫)
- **準備** 每棵植物成為可拖放物件
- **橋接** 你的 HTML 結構與 JavaScript 功能
> 🎯 **為什麼用 ID 而不用 Class?** ID 是專屬於特定元素的唯一識別碼,而 CSS 的類別(class)主要是用來對多個元素做樣式設定。當 JavaScript 需要操作單一元素時,ID 提供了精確且效能佳的方式。
`setUpUser` 函式負責儲存使用者憑證並啟動第一次 API 呼叫。這為從設定跳轉到顯示結果提供流暢體驗。
```JavaScript
```javascript
function setUpUser(apiKey, regionName) {
// 儲存用戶憑證以供未來使用
localStorage.setItem('apiKey', apiKey);
localStorage.setItem('regionName', regionName);
// 更新用戶介面以顯示加載狀態
loading.style.display = 'block';
errors.textContent = '';
clearBtn.style.display = 'block';
//make initial call
// 使用戶憑證獲取碳排放使用數據
displayCarbonUsage(apiKey, regionName);
}
```
此函數設置了一條加載消息,以在調用 API 時顯示。到目前為止,你已經到達了創建這個瀏覽器擴展最重要的函數!
### 顯示碳使用數據
最後,是時候查詢 API 了!
在進一步之前,我們應該討論 API。API,即[應用程序編程接口](https://www.webopedia.com/TERM/A/API.html),是網頁開發者工具箱中的關鍵元素。它們為程序之間的交互和接口提供了標準方式。例如,如果你正在構建一個需要查詢數據庫的網站,可能有人已經為你創建了一個 API 可以使用。雖然 API 有很多類型,其中一種最流行的是 [REST API](https://www.smashingmagazine.com/2018/01/understanding-using-rest-api/)。
✅ "REST" 代表 "表現性狀態轉移",其特點是使用不同配置的 URL 來獲取數據。研究一下開發者可用的各種 API 類型。哪種格式最吸引你?
[](https://youtube.com/watch?v=YwmlRkrxvkk "Async and Await for managing promises")
> 🎥 點擊上圖觀看 async/await 教學影片。
### 🔄 **教學檢核點**
**非同步程式設計理解**:進入 API 函式前,請確認你理解:
- ✅ 為什麼用 `async/await` 而非阻塞整個擴充
- ✅ 如何用 `try/catch` 優雅處理網路錯誤
- ✅ 同步與非同步作業的差異
- ✅ 為何 API 呼叫可能失敗及錯誤處理方法
**現實生活類比**:想想日常非同步情境:
- **訂餐**:你不會在廚房等餐,拿到收據去做其他事
- **寄郵件**:郵件發送時 app 不會凍結,可以繼續寫新郵件
- **載入網頁**:圖片漸進式載入,你已可閱讀文字
**API 認證流程**:
```mermaid
sequenceDiagram
participant Ext as Extension
participant API as CO2 Signal API
participant DB as 資料庫
Ext->>API: 使用認證令牌請求
API->>API: 驗證令牌
API->>DB: 查詢碳排放數據
DB->>API: 回傳數據
API->>Ext: JSON 回應
Ext->>Ext: 更新介面
```
建立抓取並顯示碳排放數據的函式:
```javascript
// 現代 fetch API 方法(無需外部依賴)
async function displayCarbonUsage(apiKey, region) {
try {
await axios
.get('https://api.co2signal.com/v1/latest', {
params: {
countryCode: region,
},
headers: {
'auth-token': apiKey,
},
})
.then((response) => {
let CO2 = Math.floor(response.data.data.carbonIntensity);
//calculateColor(CO2);
loading.style.display = 'none';
form.style.display = 'none';
myregion.textContent = region;
usage.textContent =
Math.round(response.data.data.carbonIntensity) + ' grams (grams C02 emitted per kilowatt hour)';
我們在這些課程中討論了幾種 API 類型。選擇一個網頁 API,深入研究它提供的功能。例如,查看瀏覽器中可用的 API,例如 [HTML 拖放 API](https://developer.mozilla.org/docs/Web/API/HTML_Drag_and_Drop_API)。在你看來,什麼樣的 API 是優秀的?
擴展你對 API 的認識,探索豐富的瀏覽器 API 來進行網頁開發。從以下瀏覽器 API 選擇一個,並建立一個小型示範:
使用 API 可以非常有趣。這裡有一個[免費 API 的列表](https://github.com/public-apis/public-apis)。選擇一個 API,並建立一個解決問題的瀏覽器擴展。這個問題可以很小,例如缺乏足夠的寵物圖片(可以試試 [dog CEO API](https://dog.ceo/dog-api/)),或者是更大的問題——盡情享受吧!
API 為創意網站開發帶來無限可能!在此作業中,你將選擇一個外部 API,然後建立一個解決實際問題或為用戶提供有價值功能的瀏覽器擴充功能。
## 指示
### 第 1 步:選擇你的 API
從此精選的[免費公開 API 清單](https://github.com/public-apis/public-apis)中選擇一個 API。考慮以下類別:
**初學者熱門選擇:**
- **娛樂**:[Dog CEO API](https://dog.ceo/dog-api/) ,隨機狗狗圖片
路由是 Web 開發中意外棘手的部分之一,尤其隨著網頁從頁面重新整理行為轉向單頁應用程式頁面更新。閱讀一下 [Azure 靜態 Web 應用服務](https://docs.microsoft.com/azure/static-web-apps/routes/?WT.mc_id=academic-77807-sagibbon) 如何處理路由。你能解釋為何該文件中描述的一些決策是必要的嗎?