1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
| <!DOCTYPE html> <html> <head> <meta > <meta > <title>计算程序</title> <link > <script ></script> </head> <style> .main{ width:400px; margin:100px auto auto auto; box-shadow:1px 1px 10px rgba(0,0,0,0.1) } </style> <body> <script> const root = document.body const home = function () { let 计算位数 = 2, 混合运算 = [1], 计算范围 = [1,10], 小数位数 = 0, 算式数值 = [], 符号数值 = [], 题目数值 = [], 题字符串 = "", 考察题库 = [], 记忆存储 = {}, 状态绑定 = { value: "", setValue: function(v) {状态绑定.value = v} }; let 随机数 = function (min,max){ if(小数位数>0) return ((Math.random()*(max-min)+min)).toFixed(小数位数) else return Math.floor(Math.random()*(max-min)+min) } let 生成算式数组 = function(){ let 算式数值 = [] for(let i=0;i<计算位数;i++){ 算式数值.push(随机数(计算范围[0],计算范围[1])) } return 算式数值 } 算式数值 = 生成算式数组() let 生成符号数组 = function(){ let 符号数组 = [] let 符号数组2 = [] for(let i=0;i<计算位数-1;i++){ if(混合运算.length == 1) 符号数组.push(混合运算[0]) else if(混合运算.length >= 2){ let 概率指数 = Math.floor(随机数(0,混合运算.length)) 混合运算.map((value,index)=>{ if(index==概率指数) 符号数组.push(value) }) } } 符号数组.map((value,index)=>{ if(value==1) 符号数组2.push("+") if(value==2) 符号数组2.push("-") if(value==3) 符号数组2.push("*") if(value==4) 符号数组2.push("/") }) return 符号数组2 } let 生成题目数组 = function() { let 题目数组=[] 算式数值.map((value,index)=>{ 题目数组.push(value) 题目数组.push(符号数值[index]) }) 题目数组.pop() return 题目数组 } let 更新题目 = function () { 符号数值 = 生成符号数组() 题目数值 = 生成题目数组() 题字符串 = 题目数值.toString().replace(/,/g,'') 考察题库[0] = { Que: 题字符串, Ans: eval(题字符串), } 考察题库.push({ Que: 题字符串, Ans: eval(题字符串), }) } 更新题目() let 批改 = function(vnode){ if(状态绑定.value == ""){} else{ if(状态绑定.value == 考察题库[0].Ans){ 更新题目() return "答案正确" } else return "答案错误" } } console.log(算式数值) console.log(符号数值) console.log(考察题库) return { view: () => m(".main",[ m(".message.is-primary",[ m(".message-header",[ m("p","计算程序"), m("button.delete",{onclick:function(){ window.close() }}) ]), m(".message-body",[ m(".field.has-addons.has-addons-centered",[ m(".control",m("a.button.is-static","问题")), m(".control.is-expanded",m("input.input.is-primary.is-expanded[type=text]",{ value:考察题库[0].Que + "=?" })), ]), m(".field.has-addons.has-addons-centered",[ m(".control",m("a.button.is-static","回答")), m(".control.is-expanded",m("input.input.is-primary[type=text][placeholder=请输入答案♪(・ω・)ノ]",{ oninput:m.withAttr("value", 状态绑定.setValue), value:状态绑定.value })), ]), m(".field.is-grouped.is-grouped-right",[ m(".control",m("button.button.is-primary","设置")), m(".control",m("button.button.is-primary.is-outlined","状态")) ]), m(".article.message",[ m({ view:function(vnode){ return m(`#tips.message-body${状态绑定.value == ""?".is-hidden":""}`,批改(vnode)) }}) ]) ]) ]) ]) } } m.mount(root, home) </script> </body> </html>
|