許瑄芠
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # 🗞 8/13 (五) - 函式傳參數、return 練習 ###### tags: `JavaScript 必修篇 - 前端修練全攻略` 本日對應章節為:函式 function。 ## function 章節複習 歡迎同學複製以下程式碼丟進開發人員工具或 CodePen 觀察執行情況唷! ### 觀念一: 函式參數介紹 ([參考章節](https://courses.hexschool.com/courses/202011122/lectures/33556275)) ```javascript= function a(num, num2) { console.log(num); console.log(num2); } a(1, 2);//呼叫並帶入參數至函式 a(num 為1、num2 為2) a(3, 4);//(num 為3、num2 為4) //觀念補充:參數只存活在大括號 console.log(num)//會被誤會成是變數,但沒有 num 這個變數,會報錯 ``` ### 觀念二: 參數寫法-兩個數字相加工具 ([參考章節](https://courses.hexschool.com/courses/202011122/lectures/33556277)) 同學可以嘗試呼叫想相加的數值,並觀察結果: ```javascript= function add(num1,num2){ console.log(`您加總的數字為${num1+num2}`) } add(2,3); ``` ### 觀念三: return 寫法教學 ([參考章節](https://courses.hexschool.com/courses/202011122/lectures/33556279)) ```javascript= function calcTotalScore(chineseScore,mathScore){ return chineseScore + mathScore; //回傳,會把值回傳到呼叫 calcTotalScore 的地方 } // return 回傳後的值,可以被賦予在變數上 //我宣告一個變數,名為 markTotalScore,並賦予右邊函式的值。 let markTotalScore = calcTotalScore(40,60);//會先將參數丟進 calcTotalScore 運算後,接收 return 回傳的值 console.log(markTotalScore)//100 ``` ### 觀念四: return 可以有多個 ([參考章節一](https://courses.hexschool.com/courses/202011122/lectures/33556281)、[參考章節二](https://courses.hexschool.com/courses/202011122/lectures/33556282)) 範例一: return 會中斷函式執行,後面的程式碼不會執行 ```javascript= function calcTotalScore(chineseScore,mathScore){ return chineseScore + mathScore; //return 會中斷該函式 /*此分隔線以下都不會執行*/ console.log('123'); return 123; } let shannonScore = calcTotalScore(80,20); ``` 範例二:搭配 if else if 可以撰寫多個 return ```javascript= // 檢查學生成績是否及格的函式 function checkScore(score){ if(score >= 60){ return '及格'; }else{ return '不及格'; } console.log('123');//因為前方有 return 中斷函式,所以不會執行 } let shannonScore = checkScore(50); console.log(shannonScore)//不及格 let tomScore = checkScore(80); console.log(tomScore)//及格 ``` ## 問題 ### 題目一 請同學參考觀念二 - 參數寫法-兩個數字相加工具後,撰寫出兩個數字**相減**工具,並透過 return 的方式,賦予回傳的值至以下變數: ```javascript= let num; ``` ### 題目二(已修正) 情境題: 炎炎夏日,小格到豆花專賣店前想吃一碗豆花: * 豆花內用售價為 56 元 * 豆花外帶售價為 61 元 * 小格現有財產為 60 元 參數對照表: > num 豆花數量 >price 豆花售價 >isTakeout 是否外帶 於是小格寫出以下程式碼想判斷自己能不能購買成功! 請同學參考以上四個 function 觀念,協助小格使用 console.log 印出結果。 ```jsx= function checkOrder(num, price, isTakeout) { if (isTakeout === true) { if (calTotal(num, price) <= 60) { return "外帶成功!"; } else { return "外帶失敗!"; } } else if (isTakeout === false) { if (calTotal(num, price) <= 60) { return "內用成功!"; } else { return "內用失敗!"; } } else { return "用餐方式輸入錯誤!"; } } function calTotal(num, price) { return num * price; } //情境一:小格想內用一碗豆花 //請呼叫 checkOrder 函式並依照情境帶入參數 //使用下方 console.log() 印出結果 console.log(); //情境二:小格想外帶一碗豆花 //請呼叫 checkOrder 函式並依照情境帶入參數 //使用下方 console.log() 印出結果 console.log(); ``` ## 回報流程 Fork 一份此[範例](https://codepen.io/jmkhsutp/pen/bGWzrOg?editors=0010)(已修正),並將答案寫在 CodePen 複製 CodePen 連結貼至下方作業投稿區中回報就算完成了喔! ![](https://firebasestorage.googleapis.com/v0/b/hexschool-courses.appspot.com/o/course%2FJS%20%E5%89%8D%E7%AB%AF%E4%BF%AE%E7%B7%B4%E5%85%A8%E6%94%BB%E7%95%A5%2F1626949627141-codepen6.png?alt=media&token=5ec398cf-adb6-4f49-a4d5-5eafc89f7441) ## 作業投稿區(學員自行投稿) 1. [範例投稿](https://codepen.io/jmkhsutp/pen/QWvYMoM?editors=0010)(可點此連結觀看解答) 2. [Shelly](https://codepen.io/shellyhwung/pen/vYmPGVy) 3. [Jane Lin](https://codepen.io/as60160/pen/yLbwJRy) 4. [Mimino](https://codepen.io/mimino/pen/PomLGPg?editors=0011) 5. [teddy wu](https://codepen.io/hongwei0522/pen/oNWVwzB?editors=0011) 6. [Shoppingq](https://codepen.io/shoppingq/pen/KKmEqvL) 7. [Bucky](https://codepen.io/bucky0112/pen/WNjmOGY?editors=0012) 8. [詠銓](https://codepen.io/GGfish26/pen/dyWrRaJ?editors=0012) 9. [肉鬆](https://codepen.io/klrkicog/pen/JjNzJwJ?editors=1011) 10. [JarvisYu](https://codepen.io/jarvis1993/pen/WNjmOLq) 11. [Yunei](https://codepen.io/Yunei/pen/abWMyow) 12. [陳sam](https://codepen.io/euldpliv/pen/WNjmEQN?editors=1111) 13. [Allen Lin](https://codepen.io/lcf7891/pen/zYwbzmK?editors=0011) 14. [Jack](https://codepen.io/yxzzktmb/pen/GRmevqz?editors=0011) 15. [InchIK](https://codepen.io/inchik-the-styleful/pen/qBmvXWV?editors=0012) 16. [LMY](https://codepen.io/l_umei/pen/BaRbdKg) 17. [Wei](https://codepen.io/tartle120/pen/vYmPZad) 18. [JuneFish](https://codepen.io/yyfish1414/pen/VwbRzqN?editors=0011) 19. [Arista](https://codepen.io/arista-hsieh/pen/abWMLwM?editors=0011) 20. [Chiang](https://codepen.io/ChiangJ/pen/jOmJGqG?editors=0011) 21. [Sandy](https://codepen.io/Sandy_L/pen/xxdBXLN?editors=0012) 22. [予予](https://codepen.io/kiqzcraa/pen/oNWVGyX?editors=0012) 23. [Judy Wei](https://codepen.io/Judy0718/pen/LYyazJE?editors=0011) 24. [axlrock1021](https://codepen.io/andy1021/pen/LYyaONR) 25. [Eva](https://codepen.io/hiYifang/pen/JjNzOaW?editors=0012) 26. [黃士桓](https://codepen.io/shr-huan-huang/pen/KKmEZQg?editors=0011) 27. [群嘉](https://codepen.io/efzdamnp-the-lessful/pen/xxdBpYj?editors=1011) 28. [Howard](https://codepen.io/yawdnhbm/pen/abWMEQK) 29. [Ulysses](https://codepen.io/dullshen/pen/YzVgxBb?editors=0011) 30. [andersonshen](https://codepen.io/luxyenni-the-bold/pen/poPYaQO) 31. [Bear](https://codepen.io/adaibear/pen/ZEKPoJe) 32. [Izumi 泉](https://codepen.io/izumi-dev/pen/jOmJxeV?editors=0011) 33. [中年大叔](https://codepen.io/adens123/pen/ExmMRez?editors=0011) 34. [LALA](https://codepen.io/bobee/pen/MWmxBKR?editors=0012) 35. [curry](https://codepen.io/Ted19851223/pen/eYWXjEY) 36. [Joe Kuo](https://codepen.io/alertislow/pen/wvdOjja?editors=0011) 37. [皮皮](https://codepen.io/super-shrimp/pen/qBmvyQm?editors=0011) 38. [Willy](https://codepen.io/cswilly901508/pen/WNjmgWG) 39. [weiliang](https://codepen.io/k7741118/pen/VwbRBRy) 40. [草皮](https://codepen.io/twgrass/pen/zYwbmNm?editors=0012) 41. [wind](https://codepen.io/wind7y/pen/VwbREWw) 42. [番茄](https://codepen.io/Tomato451321-W/pen/qBmvLMy) 43. [Nick](https://codepen.io/nick-lin/pen/mdmooWB) 44. [Lucien](https://codepen.io/Kesiang/pen/LYyawEO?editors=0011) 45. [LOMO](https://codepen.io/lockinglomo/pen/zYwbvmo) 46. [Fred](https://codepen.io/fred8196/pen/GRmLpgm?editors=0012) 47. [乃萱](https://codepen.io/nainaikuo/pen/XWRQdZx?editors=0011) 48. [Allensph](https://codepen.io/allensph/pen/KKmYMpx) 49. [Yue](https://codepen.io/Nick-Yo/pen/YzVMGPa?editors=0011) 50. [kimn](https://codepen.io/kimn/pen/eYWoROx?editors=1011) 51. [Hedy](https://codepen.io/babogooyache/pen/YzVMxQj) 52. [Rain Liao](https://codepen.io/billpop741/pen/MWmROox) 53. [DoraYu](https://codepen.io/dora-yu/pen/wvdOPgx?editors=1011) 54. [Rogan](https://codepen.io/kigwnlyg/pen/JjNVwLO?editors=1111) 55. [Yu Sung](https://codepen.io/kevin-hsu-the-encoder/pen/BaREvjv) 56. [AmberCYT](https://codepen.io/amberTing/pen/zYwXQYp?editors=0011) 57. [肉魚](https://codepen.io/zoechen13/pen/PomvomK?editors=0010) 58. [ans9323052](https://codepen.io/ans9323052/pen/PomvZJX?editors=0011) 59. [shehome](https://codepen.io/ks0dcongra/pen/rNmgzRy?editors=0012) 60. [yojanni](https://codepen.io/unayo/pen/abWrEPy?editors=0012) 61. [Margo](https://codepen.io/MargoMin/pen/vYmMdLq?editors=0012) 62. [陳茄](https://codepen.io/TomatoIN/pen/JjNqzGq?editors=0010) 63. [zhaoJames](https://codepen.io/james-zhao/pen/ZEKdGYB?editors=0011) 64. [Susan](https://codepen.io/susanbnak/pen/oNWrbYZ) 65. [Yiren](https://codepen.io/Yiren_Liou/pen/oNWrLjr) 66. [janice](https://codepen.io/janice880624/pen/vYmqyvq) 67. [Amber_Lin](https://codepen.io/autum55853/pen/GRmVwwZ?editors=0011) 68. [Wilson Han](https://codepen.io/wi0821/pen/jOwNmGN?editors=0012) 69. [YinChenCheng](https://codepen.io/yinchengchen/pen/RwgbxeV?editors=0011) 70. [Jung](https://codepen.io/ROUJUNG/pen/WNONGyz?editors=0012) 71. [Shiny](https://codepen.io/shinychen/pen/dyRPggv) 72. [安迪](https://codepen.io/andyang1030/pen/PojwgLb?editors=0010) 73. [Peter](https://codepen.io/peter_hung/pen/powJzpq) 74. [claire](https://codepen.io/yi-wen-chen/pen/gORarrM) 75. [Eileen](https://codepen.io/Eileen-Ching/pen/VwWKQvQ?editors=0010) 76. [SeanChang](https://codepen.io/seanchang7/pen/vYZyjeX?editors=0012) 77. [莎賓娜](https://codepen.io/a120220ms25/pen/qBjqYPE?editors=0011) 78. [LucieW](https://codepen.io/Lucie_W/pen/eYRgLwo) 79. [PeggyTsai](https://codepen.io/pei-chi-tsai/pen/qBjXKLe?editors=0010) 80. [Joy Cheng](https://codepen.io/joycheng5432/pen/BaZmRyg?editors=1011) 81. [Gill](https://codepen.io/Gill-Chin/pen/GREyaZB) 82. [WA](https://codepen.io/ldddl/pen/dyRwzRN) 83. [Tim](https://codepen.io/jake1155/pen/WNOWxEv) 84. [else](https://codepen.io/ningfleur/pen/MWoLXgN?editors=0011) 85. [Kmberly](https://codepen.io/KIMBERLY_Yen/pen/ZEJeWYO) 86. [betty Chen](https://codepen.io/Ying-Tzu/pen/BadqeVY?editors=0010) 87. [Will](https://codepen.io/ncrdpepc-the-lessful/pen/mdMQbQM) 88. [Sunny](https://codepen.io/Sunny0509/pen/PoKMpZN?editors=0011) 89. [BrunoYu](https://codepen.io/bruno-yu/pen/JjrWjYX?editors=0012) 90. [Hailey](https://codepen.io/aojprock/pen/oNGZoeZ?editors=1011) 91. [RuoAn](https://codepen.io/LiauRuoAn/pen/ZEXexqG?editors=0012) 92. [庭瑋](https://codepen.io/wei_wu/pen/yLzdoRe?editors=0012) 93. [JimmyFang](https://codepen.io/pohxiqqo/pen/LYOQVPz?editors=0012) 94. [Min](https://codepen.io/minnn7716/pen/rNYRXMo) 95. [Jay](https://codepen.io/JayWang123/pen/JjOgGme) 96. [沈依蓉](https://codepen.io/lily-oa/pen/mdpyxqr?editors=0011) 97. [Alice](https://codepen.io/Charlotte0805/pen/KKZVJMJ?editors=0010) 98. [int Huang](https://codepen.io/intHuang/pen/OJQLxbv?editors=0011) 99. [Peihan Wang](https://codepen.io/PeihanWang/pen/WNMvYwK?editors=0011) 100. [JackC](https://codepen.io/key0329/pen/bGLgPbQ?editors=0012) 101. [Cindy Huang](https://codepen.io/cindyhuang888/pen/eYVGZje?editors=0011) 102. [Kevin Jiang](https://codepen.io/xlqjezvc-the-encoder/pen/wvypdpO?editors=0012) 103. [shio](https://codepen.io/shioyen/pen/eYVjRZX?editors=0011) 104. [sophielam](https://codepen.io/sophiee2727/pen/xxYmLpx?editors=0011) 105. [YI](https://codepen.io/YI0305/pen/YzaVPYq?editors=0012) 106. [0808jessie](https://codepen.io/0808jessie/pen/zYWzgEL?editors=0012) 107. [Cliff](https://codepen.io/Cliff_hex/pen/yLKPEwE?editors=0011) 108. [Winnie](https://codepen.io/TzuHsuanWu/pen/KKoxBBp?editors=0010) 109. [Cary](https://codepen.io/yi-chien-hsieh/pen/eYMwMGg?editors=0012) 110. [amy](https://codepen.io/amy-chieng/pen/PoeGQWj) 111. [Anna](https://codepen.io/pen/?editors=1112) 112. [Alex](https://codepen.io/datsxzqg-the-selector/pen/wvjpPMR?editors=0012) 113. [piha](https://codepen.io/pihahaha/pen/poVVKWr) 114. [sasimi](https://codepen.io/sashimi1327/pen/dyeEXpo) 115. [qoq77416416](https://codepen.io/qoq77416416/pen/poKbMJx?editors=0012) 116. [Eden](https://codepen.io/Eden-C/pen/PoBXoNE) 117. [yunifer](https://codepen.io/yunifer1227022/pen/XWBwpvo) 118. [chih](https://codepen.io/ftbvujte-the-styleful/pen/gOdRvpE?editors=0012) 119. [KiKi](https://codepen.io/ki-ki-the-builder/pen/YzBbxRW) 120. [HaoJing](https://codepen.io/hjxu/pen/RwdPNOY?editors=0011) 121. [wei](https://codepen.io/Wei-the-sasster/pen/gOyXYXN?editors=0011) 122. [ABEI](https://codepen.io/uwmrsusb-the-solid/pen/MWMKPwY) 123. [qqprzi](https://codepen.io/qqorzi/pen/zYVPJXV) 124. [William](https://codepen.io/lsaimqxa-the-vuer/pen/zxxJoGy?editors=0012)

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully