# [LeetCode 75] DAY 1 - Merge Strings Alternately
## 題目:1768. Merge Strings Alternately
You are given two strings `word1` and `word2`. Merge the strings by adding letters in alternating order, starting with `word1`. If a string is longer than the other, append the additional letters onto the end of the merged string.
Return the merged string.
## 解題思考
- 需要合併兩個字串:宣告一個空變數或空陣列
- 需要判斷 word1 word2 的最大值:Math.max
- 依序從 `i = 0`將 word1 word2 的字元放入空變數中
- 直到 i = word1.length
- 直到 i = word2.length
## 程式碼
```javascript
function mergeAlternately (word1, word2) {
const result = '';
const longest = Math.max(word1.length, word2.length);
for (let i = 0; i < longestWord; i++){
if (i < word1.length){
result += word1[i]
}
if (i < word2.length){
result += word2[i]
}
}
return result;
}
```
## 相關資源
- [1768. Merge Strings Alternately](https://leetcode.com/problems/merge-strings-alternately/description/)