{"id":53309,"student_id":10,"content":"{\"html\":\"\u003c!DOCTYPE html\u003e\\n\u003chtml\u003e\\n\u003chead\u003e\\n \u003ctitle\u003eDocument\u003c/title\u003e\\n \u003clink rel=\\\"stylesheet\\\" href=\\\"https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css\\\"\u003e\\n\u003c/head\u003e\\n\u003cbody class=\\\"p-4\\\"\u003e\\n \u003cp\u003e\u003c/p\u003e\\n \u003cspan class=\\\"pb-4 align-center\\\"\u003e\\n \u003cbutton class=\\\"btn btn-primary\\\" onclick=\\\"yes();ask();\\\"\u003e是\u003c/button\u003e\\n \u003cbutton class=\\\"btn btn-danger\\\" onclick=\\\"no();ask();\\\"\u003e不是\u003c/button\u003e\\n \u003cbutton class=\\\"btn btn-secondary\\\" onclick=\\\"unknow();ask();\\\"\u003e不知道\u003c/button\u003e\\n \u003c/span\u003e\\n\u003c/body\u003e\\n\u003c/html\u003e\",\"css\":\"body {\\n width: 100vw;\\n height: 100vh;\\n}\\n\\n.right span, .left span {\\n display: inline-block;\\n max-width: 75%;\\n padding: 8px;\\n border-radius: 20px;\\n font-size: .9rem;\\n border-radius: .9rem;\\n}\\n\\n.right {\\n text-align: right;\\n}\\n\\n.right span {\\n color: #fff;\\n background-color: rgb(59, 114, 241);\\n}\\n\\n.left span {\\n color: #555;\\n background-color: rgb(210, 210, 210);\\n}\\n\\n\",\"js\":\"var tagsData = [\\\"戴眼鏡\\\", \\\"結婚\\\", \\\"男性\\\", \\\"藝人\\\", \\\"政治人物\\\", \\\"網紅\\\"]\\nvar database = {\\n \\\"柯文哲\\\": {\\n has: [\\\"戴眼鏡\\\", \\\"結婚\\\", \\\"男性\\\", \\\"政治人物\\\"],\\n not: [\\\"藝人\\\"]\\n },\\n \\\"周杰倫\\\": {\\n has: [\\\"結婚\\\", \\\"男性\\\", \\\"藝人\\\"],\\n not: [\\\"戴眼鏡\\\", \\\"政治人物\\\"]\\n },\\n \\\"小玉\\\": {\\n has: [\\\"網紅\\\", \\\"男性\\\"],\\n not: [\\\"戴眼鏡\\\", \\\"政治人物\\\", \\\"結婚\\\"]\\n }\\n}\\n\\nvar data; // 儲存名人的資料\\nvar tags; // 儲存名人擁有的屬性\\nvar Q; // 儲存當前問題的內容\\n\\nfunction start () {\\n say('現在請你在心中想一個台灣的名人,讓我問幾個是/不是的問題就能猜出你在想誰!', 'left');\\n data = JSON.parse(JSON.stringify(database)); // 複製 database 資料到 data 變數中\\n tags = JSON.parse(JSON.stringify(tagsData)); // 複製 tagsData 資料到 tags 變數中\\n ask();\\n}\\n\\n// 執行 ask 函式使機器人問出一個 是/不是 的問題\\nfunction ask () {\\n\\n var best;\\n var bestScore = 0;\\n\\n for (var i = 0; i \u003c tags.length; i++) {\\n var total = 0;\\n var has = 0;\\n var not = 0;\\n for (var name in data) {\\n if (data[name].has.includes(tags[i])) has++;\\n if (data[name].not.includes(tags[i])) not++;\\n total++;\\n }\\n\\n var score = has*not/total;\\n\\n if (score \u003e bestScore) {\\n bestScore = score;\\n best = tags[i];\\n }\\n }\\n \\n // 將問過的問題從 tags 中移除\\n var idx = tags.indexOf(best);\\n tags.splice(idx, 1);\\n\\n if (best !== undefined) {\\n Q = best;\\n } else { // 如果沒有合適的問題就開始猜人名\\n Q = Object.keys(data)[0];\\n }\\n\\n say(`請問他是${Q}嗎?`, 'left');\\n}\\n\\n// 點擊「是」按鈕會觸發執行 no 函式\\nfunction yes () {\\n for (var name in data) {\\n if (data[name].not.includes(Q)) delete data[name];\\n }\\n say('是', 'right');\\n}\\n\\n// 點擊「不是」按鈕會觸發執行 no 函式\\nfunction no () {\\n for (var name in data) {\\n if (data[name].has.includes(Q)) delete data[name];\\n }\\n delete data[Q];\\n say('不是', 'right');\\n}\\n\\n// 點擊「不知道」按鈕會觸發執行 unknow 函式\\nfunction unknow () {\\n delete data[Q];\\n say('不知道', 'right');\\n}\\n\\nsay('你好,我是讀心人工智能機器人!', 'left')\\nstart();\"}","created_at":"2019-01-05T14:53:39.171+08:00","updated_at":"2019-11-10T14:16:45.911+08:00","name":"20Q 預設專案","language":"web","screenshot":{"url":"/uploads/project/screenshot/53309/3af9f6a83da75a38ca9e60cc2104076d.jpg"},"parent_id":52890,"plugin":"function say (text, style) {\n var p = document.getElementsByTagName('p')[0];\n p.innerHTML += `\n \u003cp class=\"${style || 'right'}\"\u003e\n \u003cspan\u003e${text}\u003c/span\u003e\n \u003c/p\u003e\n `\n window.scrollTo(0,document.body.scrollHeight);\n}\n\n\n","description":null,"note":null,"status":"public","like_student_ids":[],"is_featured":false,"views":536,"hashid":"meysgjdz","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[{"id":951071,"file_name":"koding.png","project_id":53309,"asset_id":103489,"created_at":"2019-01-05T14:53:39.181+08:00","updated_at":"2019-01-05T14:53:39.181+08:00"}]
Orange Apple Learning Platform
My Projects
View Project Page
Export
Remix
Import
Delete
Download Android APP (APK)
Screenshot
Open Web Site
繁中
简中
English
日本語
1:1:1
1:1
Full Width
Scan the QRCode below with your phone to install
Or you can
download APK
to this computer
Scan the QRCode below with your phone to install
Or you can
download APK
to this computer