這是一個假設打印安全或淘汰的作業,具體取決於total3是否大於或小於total4。我的if語句給出了錯誤的答案
var c4 =5;
var c5 =1;
var c6 =4;
var d4 =1;
var d5 =11;
var d6 =1;
var total3 = c4+c5+c6;
var total4 = d4+d5+d6;
var printResult = function(player,dealer){
var game1 = "Player: "+total3 +", Dealer: "+total4;
return game1;
}
if (total3 > total4){
total3 = 'safe';
total4 = 'busted';
}
if (total4 > total3) {
total4 = 'safe';
total3 = 'busted';
}
ANSWER = printResult(total3,total4);
我得到的答案是: 「玩家:搗毀,經銷商:安全」
但我猜想得到的答覆是: 「玩家:安全經銷商:安全」
任何有助於理解它爲什麼不按預期工作的讚賞!
當您使用內置於瀏覽器中的調試程序運行代碼時,您會看到什麼代碼? – 2015-02-10 13:54:34
*真的*閱讀你的陳述。如果兩個都是「安全的」,你**不能**得到結果。 – deceze 2015-02-10 13:55:26
爲什麼人們仍然認爲我們在這裏調試他們的代碼? – melancia 2015-02-10 13:56:06