Microbit Jack
    • 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
    ###### tags: `JS學徒特訓班` # Day7 if - 認真的小杰竟被客訴 昨天老闆說他收到客訴,客戶們都一致反應小杰的態度不好,這讓小杰感到黑人問號。 後來發現的原因是,在之前 VIP 活動,小杰 都是這樣回覆客戶 `console.log("Bob 的 VIP 條件為 true")` 客戶A:「true 什麼鬼..可以說中文嗎?」 客戶B:「是瞧不起我嗎?老闆我好歹跟你有五年交情,我兒子都來你這邊吃飯欸!」 於是老闆斥責小杰,要求他講中文,於是給了他以下資源,要他好好學 if 這個工具。 ## 教學連結 * [重新認識 JavaScript: Day 09 流程判斷與迴圈](https://ithelp.ithome.com.tw/articles/10191453) * [菜鳥教學 - if else(用 Chrome 翻譯繁體)](https://www.runoob.com/js/js-if-else.html) * [JS 判斷筆記](https://medium.com/%E9%A6%AC%E6%A0%BC%E8%95%BE%E7%89%B9%E7%9A%84%E5%86%92%E9%9A%AA%E8%80%85%E6%97%A5%E8%AA%8C/js-%E5%88%A4%E6%96%B7%E7%AD%86%E8%A8%98-%E9%81%8B%E7%AE%97%E5%AD%90-if-switch-a9f5e535835b) * [if 簡報教學](https://courses.hexschool.com/courses/670042/lectures/11952274) * [if 程式碼教學](https://courses.hexschool.com/courses/670042/lectures/11952275) * [else if 簡報教學](https://courses.hexschool.com/courses/670042/lectures/11952278) * [else if 程式碼教學](https://courses.hexschool.com/courses/670042/lectures/11952282) # 題目 ## 題目一:if 的練習 老闆說現在要來驗收 if 成果, 成為 VIP 會員的條件,只要購買滿 200 元, 現在 客戶 A 購買了 350 元,請用 if 判斷是否要給他 VIP 卡。 ``` var VIPTotal = 200; var memberPrice = 350; // 請透過 if 來設計回覆,如果對方滿足門檻 // 就回覆 console.log("您好,您有達到 VIP 門檻。這裡給您 VIP 會員卡(遞上") ``` ## 題目二:if else 的練習 又有人來申請 VIP 活動了! 成為 VIP 會員的條件,只要購買滿 200 元,就可無條件成為會員,Mark 買了 2 個漢堡,2 個 薯條,是否有滿足條件? 這次要記得用 if,以及注意你的語氣啊~ (小杰覺得人生好難 ``` var VIPTotal = 200; var hamburgerPrice = 50; var friesPrice = 30; // 請透過 if else 來去設計對方是否有達到條件,有或沒有都需要回覆對方 // 如果有,請顯示 console.log("尊敬的客戶您好,您有達到 VIP 條件") // 如果沒有達到條件,便用 else 顯示 console.log("尊敬的客戶您好,您還差 xx 元,才有符合 VIP 條件哦~") ``` ## 題目三: if、else if、else 練習 工作一整天,小杰累到懷疑人生,累歸累,但還是得吃東西,小杰吃東西有自己的 SOP,來幫幫小杰看看他該吃什麼食物。 * 小杰都用飢餓度 1~100 來計算,100 就是代表最飢餓 * 小杰飢餓度 0~20 時,都吃飯糰 * 小杰飢餓度在 21~40 時,都吃肉燥飯+貢丸湯 * 小杰飢餓度在 41~60 時,都吃麥當勞 * 小杰飢餓度在 61~100 時,都吃 99 元火鍋吃到飽 今天小杰的飢餓度是 53,請引導小杰去指定地點用餐 ``` var hungryNum = 53; if(條件式){ console.log(); }else if{ console.log(); } // 請用 if、else if 去判斷主人公該吃什麼 // 各區塊回覆內容請顯示 console.log("主人公因為飢餓度在"+hungryNum+",所以他決定去吃麥當勞") ``` * * * ## 題目一解答 ```javascript= var VIPTotal = 200; var memberPrice = 350; if(memberPrice >= VIPTotal) { console.log(`您好,您有達到 VIP 門檻。這裡給您 VIP 會員卡(遞上)`); } ``` ## 題目二解答 ```javascript var VIPTotal = 200; var hamburgerPrice = 50; var friesPrice = 30; var markHamburgerNum = 2; var markFriesNum = 2; var markSpendPrice = markHamburgerHum * hamburgerPrice + markFriesNum * friesPrice; if(markSpendPrice >= VIPTotal) console.log(`Mark 您好,您有達到 VIP 門檻。這裡給您 VIP 會員卡(遞上)`); else console.log(`尊敬的客戶您好,您還差 ${VIPTotal - markSpendPrice} 元,,才有符合 VIP 條件哦~`); ``` ## 題目三解答 ```javascript= var hungryNum = 53; if(hungryNum >= 0) { //若飢餓度來自於操作者輸入時 if(hungryNum <= 20) { console.log(`主人公因為飢餓度在${hungryNum}所以他決定去吃飯糰`); } else if(21 <= hungryNum && hungryNum <= 40) { console.log(`主人公因為飢餓度在${hungryNum}所以他決定去吃肉燥飯+貢丸湯`); } else if(41 <= hungryNum && hungryNum <= 60) { console.log(`主人公因為飢餓度在${hungryNum}所以他決定去吃麥當勞`); } else if(61 <= hungryNum && hungryNum <= 100) { console.log(`主人公因為飢餓度在${hungryNum}所以他決定去吃99元火鍋吃到飽`); } } else { console.log('所輸入的飢餓度有誤'); } ``` *** ## 另類解答 ```javascript= //題目二 var VIPTotal = 200, hamburgerPrice = 50, friesPrice = 30; let totalPrice = (hamburgerNum, friesNum) => hamburgerPrice * hamburgerNum + friesPrice * friesNum; let isVip = (price) => price >= VIPTotal ? true : false; let markSpendPrice = totalPrice(2, 2); let spread = VIPTotal - markSpendPrice; var msg = `尊敬的客戶您好,您還差 ${spread} 元,才有符合 VIP 條件哦~` if(isVip(markSpendPrice)) msg = `Mark 您好,您有達到 VIP 門檻。這裡給您 VIP 會員卡(遞上)`; console.log(msg); //題目三 var hungryNum = 53; function getFood(hungryNum) { var food = ''; if(hungryNum <= 20) food = '飯糰'; else if(21 <= hungryNum && hungryNum <= 40) food = '肉燥飯+貢丸湯'; else if(41 <= hungryNum && hungryNum <= 60) food = '麥當勞'; else if(61 <= hungryNum && hungryNum <= 100) food = '99元火鍋吃到飽'; else food = '' return food; } console.log(`主人公因為飢餓度在${hungryNum},所以他決定去吃${getFood(hungryNum)}`); ```

    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