gpt4 book ai didi

javascript - jQuery - 随机选择总和

转载 作者:行者123 更新时间:2023-11-30 18:12:52 25 4
gpt4 key购买 nike

我正在为小学生创建一个“打地鼠”风格的游戏,他们必须根据给定的总和点击正确的数字。

目前程序正在生成这样的加法和。

function createPlusSum(total) {
console.log(total)
var int1 = Math.ceil(Math.random() * total);
var int2 = total - int1;
$('#target').html(int1 + ' + ' + int2 + ' = ?');
}

我已经为减法再次做了这个并且它有效,但我不知道从这里开始随机化是否产生加法或减法问题。这是生成减法题的函数。

function createTakeSum(total) {
console.log(total)
var int1 = Math.ceil(Math.random() * total);
var int2 = total + int1;
$('#target').html(int2 + ' - ' + int1 + ' = ?');
}

我用它来创建加法和

createPlusSum(total);

我怎么说我想要

createPlusSum(total);

createTakeSum(total);

最佳答案

试试这个:

function createSum() {
total = Math.ceil(Math.random() * 10);
if(Math.random() > 0.5)
{
createTakeSum(total);
} else {
createPlusSum(total)
}
}

关于javascript - jQuery - 随机选择总和,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14141531/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com