--- tags: JavaScript 實戰班 --- # 轉職忍者三組-作業繳交區 ## Day 6 (6/15 任務) ### Jennie Huang(6/15 任務) 比較運算子 :https://developer.mozilla.org/zh-TW/docs/Web/JavaScript/Reference/Operators/Comparison_Operators if 判斷式:https://developer.mozilla.org/zh-TW/docs/Web/JavaScript/Reference/Statements/if…else#語法 ```javascript= function sayYouLoveMe() { return 1; } if(sayYouLoveMe() == true){ console.log('sayYouLoveMe') } //當判斷式執行 sayYouLoveMe()所回傳的值 1 與 true 做運算子比較 //因為1做運算子比較時為ture 所以程式可以繼續執行可以console.log ``` > 卡斯伯回覆:作業沒問題唷~ ### Ryu (6/15 任務) switch 判斷: https://developer.mozilla.org/zh-TW/docs/Web/JavaScript/Reference/Statements/switch ```javascript= function sayYouLoveMe() { return true; } switch (sayYouLoveMe()) { case true: console.log('說你愛我') break; case false: console.log('說你不喜歡我') break; default: console.log('說我對你沒興趣') break; } //switch會比對跟sayYouLoveMe()的值是否符合case的條件 //以及sayYouLoveMe()的值都不符合時會執行default ``` ### Nicolas (6/15 任務) if...else 語法:https://developer.mozilla.org/zh-TW/docs/Web/JavaScript/Reference/Statements/if...else ```javascript= function sayYouLoveMe() { return false; } var answer = sayYouLoveMe() if(answer){ console.log("Say you love me.") } else { console.log("Why you don't love me?") } //把 sayYouLoveMe 函式的回傳值存在變數 answer 裡 //if(answer) 裡面的 answer 是表達式 //if...else 語句,如果 answer 是 true 則印出 Say you love me., //若否則印出 Why you don't love me?。 ```
×
Sign in
Email
Password
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