"ui";
ui.layout(
<vertical>
<horizontal>
<button id="设置"text="设置"/>
<input id="数字"text="100"w="100dp"/>
<text text="内加减法"textSize="25"/>
</horizontal>
<list id="列表">
<horizontal>
<text id="名字"text="{{题}}="w="auto"/>
<input id="输入框"w="100"/>
<text id="判断"/>
</horizontal>
</list>
<button id="提交"text="提交"/>
</vertical>
);
设置题()
ui.设置.click(() => {
设置题()
})
function 设置题(){
结果 = []
let 数字 = ui.数字.text() - 0
let items = []
for (let i = 0; i < 10; i++) {
let a = random(0, 1)
let b, c, d
if (a == 0) {
b = random(0, 数字)
c = random(0, 数字 - b)
d = "+"
结果.push(b + c)
} else {
b = random(0, 数字)
c = random(0, b)
d = "-"
结果.push(b - c)
}
if (b > 0) {
items.push({
"题": b + d + c,
})
} else {
i--
}
}
ui.列表.setDataSource(items);
}
ui.提交.click(() => {
for (var i = 0; i < ui.列表.getChildCount(); i++) {
let jg = ui.列表.getChildAt(i).getChildAt(1);
let pd = ui.列表.getChildAt(i).getChildAt(2);
if (jg.getText() == 结果[i]) {
pd.setText("√")
} else {
pd.setText("×")
}
}
})
06-19
120