{"id":131500,"student_id":2002,"content":"// 點擊時取得玩家輸入\nwhen('click', function () {\n var input = prompt('猜 1 ~ 1000 數字?');\n var result = guess(input);\n console.log(result);\n});\n// function linear_search() {\n// var result2 = null;\n// for (var i = 1; i \u003c= 1000; i++) {\n// result2 = guess(i);\n// if (result2 === 0)\n// break;\n// }\n// }\nbinary_search();\nfunction binary_search() {\n var result3;\n var s = 1;\n var e = 1000;\n while (true) {\n var mid = Math.floor((s + e) / 2);\n result3 = guess(mid);\n if (result3 == 1)e = mid-1;\n if (result3 == -1)s = mid+1;\n if (result3 === 0)break;\n }\n}","created_at":"2020-03-08T13:49:27.610+08:00","updated_at":"2020-03-08T15:07:25.465+08:00","name":"終極密碼 副本","language":"javascript","screenshot":{"url":"https://cdn4.koding.school/uploads/project/screenshot/131500/89edcce60b8890776f43b51e69f48ea4.jpg"},"parent_id":31718,"plugin":"setBackdrop('black');\n\nvar guess = (function () {\n var count = 0;\n var answer = Math.ceil(Math.random()*1000);\n var recentGuess = '???';\n var result = '';\n \n function guess (num) {\n count++;\n recentGuess = num;\n \n if (num \u003e answer) {\n result = '太大了';\n return 1;\n }\n if (num \u003c answer) {\n result = '太小了';\n return -1;\n }\n if (num == answer) {\n result = '猜對了';\n return 0;\n }\n }\n \n forever(function(){\n print('猜', 80, 225, 'white', 60);\n print(recentGuess, 150, 150, 'white', 150);\n print(result, 410, 225, 'white', 60);\n print(`猜了 ${count} 次`, 400, 330, 'white', 30);\n });\n \n return guess;\n \n})();\n\n\n\n\n","description":null,"note":null,"status":"public","like_student_ids":[],"is_featured":false,"views":44,"hashid":"36ysnjyv","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[]
橘蘋學習平台
橘蘋學習平台
我的作品
檢視專案頁
匯出
複製
匯入
刪除
下載 Android APP (APK)
截圖
1:1:1
1:1
full
幫助
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦