- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我目前正在制作 STEM 数学游戏。我创建了一个函数调用 onLoad()
,它获取 20 个不重复的不同随机数,并将它们设置为变量。现在,我尝试获取该数字并将 Q
添加到其前面,因为我有不同的变量,名为 Q1
、Q2
等。但是,当我尝试 console.log 时,将两者结合起来的变量 X 全部显示为 Q1,而不是变量 Q1 中的字符串。任何帮助将不胜感激!
//Questions - Answers
var Q1 = "5 x 10<sup>7</sup> = ?";
//var A1 = "A: 50,000,000";
var A1 = "<button id='answerButton' type='button' class='reg'>A: 50,000,000</button> <button id='answerButton' type='button' class='reg'>B: 0.0000005</button><br /><br /><button id='answerButton' type='button' class='reg'>C: 5,000,000</button><button id='answerButton' type='button' class='reg'>D: 500,000</button>";
var Q2 = "3.868 x 10<sup>9</sup> = ?";
var A2 = "B: 3,868,000,000";
var Q3 = "What is the answer for 20000000 × 3.5 × 1000000 in scientific notation?";
var A3 = "A: 7 × 10<sup>13</sup>";
var Q4 = "123,000 = ?";
var A4 = "B: 1.23 x 10<sup>5</sup>";
var Q5 = "0.00123 x 10<sup>5</sup> = ?";
var A5 = "A: 12.3 x 10<sup>1</sup>";
var Q6 = "0.0686 x 10<sup>0</sup> = ?";
var A6 = "C: 0.0686";
var Q7 = "2.26 x 10<sup>5</sup> = ?";
var A7 = "B: 226,000";
var Q8 = "0.0002395 = ?";
var A8 = "C: 2.395 x 10<sup>-4</sup>";
var Q9 = "731,000 = ?";
var A9 = "A: 7.31 x 10<sup>5</sup>";
var Q10 = "0.00018 = ?";
var A10 = "B: 1.8 x 10<sup>-4</sup>";
var Q11 = "2x = 54";
var A11 = "D: x = 27";
var Q12 = "x = 81";
var A12 = "A: x = 81";
var Q13 = "4x+8=7.2+5x";
var A13 = "C: x = 0.800";
var Q14 = "4(0.5f−0.25)=6+f";
var A14 = "C: f = 7";
var Q15 = "2+6g=11−3g";
var A15 = "B: g = 1";
var Q16 = "−11f=7(1−2f)+5";
var A16 = "A: f = 4";
var Q17 = "0.5s+1=7+4.5s";
var A17 = "B: s = -1.5";
var Q18 = "2(x+3) = 16";
var A18 = "D: x = 5";
var Q19 = "21+3j = 6";
var A19 = "C: j = -5";
var Q20 = "4(x-1) = -16";
var A20 = "A: x = -3";
var Q21 = "A company charges a flat fee of 1500 dollars to rent a yacht. In addition, renters must pay 100 dollars per hour. Which equation shows the cost C to rent a yacht for h hours?";
var A21 = "C: C = 100h + 1500";
var Q22 = "What is the equation of a line that has a slope of 3/5 and a y-intercept of 2?";
var A22 = "A: 5y - 3x = 10";
var Q23 = "Make an equation for sixteen more than a number is 9.";
var A23 = "C: 16 + x = 9";
var Q24 = "There are b boys in the class. This is three more than four times the number of girls. How many girls are in the class?";
var A24 = "B: b = 3 + 4g";
var Q25 = "The sum of two numbers is 84, and one of them is 12 more than the other. What is the equation?";
var A25 = "D: x + 12 + x = 84";
var Q26 = "Anton's birthday party costs $2 for every guest he invites. Write an equation that shows the relationship between the guests x and the cost y.";
var A26 = "A: y = 2x";
var Q27 = "Allie jars 6 liters of jam every day. Write an equation that shows the relationship between the days x and the jam made y.";
var A27 = "C: y = 6x";
var Q28 = "Gabe can grow 8 flowers with every seed packet. Write an equation that shows the relationship between the number of seed packets x and the total number of flowers y.";
var A28 = "B: y = 8x";
var Q29 = "Bella's retirement party costs $6, plus an additional $1 for each guest she invites. Write an equation that shows the relationship between the guests x and the cost y.";
var A29 = "C: y = x + 6";
var Q30 = "Cole has already taken 4 pictures at home, and he expects to take 1 picture during every day of vacation. Write an equation that shows the relationship between the days of vacation x and the total number of pictures taken y.";
var A30 = "C: y = x + 4";
//Question Numbers
var N1 = Math.floor(Math.random() * 30) + 1;
var N2 = 0;
var N3 = 0;
var N4 = 0;
var N5 = 0;
var N6 = 0;
var N7 = 0;
var N8 = 0;
var N9 = 0;
var N10 = 0;
var N11 = 0;
var N12 = 0;
var N13 = 0;
var N14 = 0;
var N15 = 0;
var N16 = 0;
var N17 = 0;
var N18 = 0;
var N19 = 0;
var N20 = 0;
//On Game Load
function onLoad() {
do {
N2 = Math.floor(Math.random() * 30) + 1;
} while(N2 === N1);
do {
N3 = Math.floor(Math.random() * 30) + 1;
} while(N3 === N1 || N3 === N2);
do {
N4 = Math.floor(Math.random() * 30) + 1;
} while(N4 === N1 || N4 === N2 || N4 === N3);
do {
N5 = Math.floor(Math.random() * 30) + 1;
} while(N5 === N1 || N5 === N2 || N5 === N3 || N5 === N4);
do {
N6 = Math.floor(Math.random() * 30) + 1;
} while(N6 === N1 || N6 === N2 || N6 === N3 || N6 === N4 || N6 === N5);
do {
N7 = Math.floor(Math.random() * 30) + 1;
} while(N7 === N1 || N7 === N2 || N7 === N3 || N7 === N4 || N7 === N5 || N7 === N6);
do {
N8 = Math.floor(Math.random() * 30) + 1;
} while(N8 === N1 || N8 === N2 || N8 === N3 || N8 === N4 || N8 === N5 || N8 === N6 || N8 === N7);
do {
N9 = Math.floor(Math.random() * 30) + 1;
} while(N9 === N1 || N9 === N2 || N9 === N3 || N9 === N4 || N9 === N5 || N9 === N6 || N9 === N7 || N9 === N8);
do {
N10 = Math.floor(Math.random() * 30) + 1;
} while(N10 === N1 || N10 === N2 || N10 === N3 || N10 === N4 || N10 === N5 || N10 === N6 || N10 === N7 || N10 === N8 || N10 === N9);
do {
N11 = Math.floor(Math.random() * 30) + 1;
} while(N11 === N1 || N11 === N2 || N11 === N3 || N11 === N4 || N11 === N5 || N11 === N6 || N11 === N7 || N11 === N8 || N11 === N9 || N11 === N10);
do {
N12 = Math.floor(Math.random() * 30) + 1;
} while(N12 === N1 || N12 === N2 || N12 === N3 || N12 === N4 || N12 === N5 || N12 === N6 || N12 === N7 || N12 === N8 || N12 === N9 || N12 === N10 || N12 === N11);
do {
N13 = Math.floor(Math.random() * 30) + 1;
} while(N13 === N1 || N13 === N2 || N13 === N3 || N13 === N4 || N13 === N5 || N13 === N6 || N13 === N7 || N13 === N8 || N13 === N9 || N13 === N10 || N13 === N11 || N13 === N12);
do {
N14 = Math.floor(Math.random() * 30) + 1;
} while(N14 === N1 || N14 === N2 || N14 === N3 || N14 === N4 || N14 === N5 || N14 === N6 || N14 === N7 || N14 === N8 || N14 === N9 || N14 === N10 || N14 === N11 || N14 === N12 || N14 === N13);
do {
N15 = Math.floor(Math.random() * 30) + 1;
} while(N15 === N1 || N15 === N2 || N15 === N3 || N15 === N4 || N15 === N5 || N15 === N6 || N15 === N7 || N15 === N8 || N15 === N9 || N15 === N10 || N15 === N11 || N15 === N12 || N15 === N13 || N15 === N14);
do {
N16 = Math.floor(Math.random() * 30) + 1;
} while(N16 === N1 || N16 === N2 || N16 === N3 || N16 === N4 || N16 === N5 || N16 === N6 || N16 === N7 || N16 === N8 || N16 === N9 || N16 === N10 || N16 === N11 || N16 === N12 || N16 === N13 || N16 === N14 || N16 === N15);
do {
N17 = Math.floor(Math.random() * 30) + 1;
} while(N17 === N1 || N17 === N2 || N17 === N3 || N17 === N4 || N17 === N5 || N17 === N6 || N17 === N7 || N17 === N8 || N17 === N9 || N17 === N10 || N17 === N11 || N17 === N12 || N17 === N13 || N17 === N14 || N17 === N15 || N17 === N16);
do {
N18 = Math.floor(Math.random() * 30) + 1;
} while(N18 === N1 || N18 === N2 || N18 === N3 || N18 === N4 || N18 === N5 || N18 === N6 || N18 === N7 || N18 === N8 || N18 === N9 || N18 === N10 || N18 === N11 || N18 === N12 || N18 === N13 || N18 === N14 || N18 === N15 || N18 === N16 || N18 === N17);
do {
N19 = Math.floor(Math.random() * 30) + 1;
} while(N19 === N1 || N19 === N2 || N19 === N3 || N19 === N4 || N19 === N5 || N19 === N6 || N19 === N7 || N19 === N8 || N19 === N9 || N19 === N10 || N19 === N11 || N19 === N12 || N19 === N13 || N19 === N14 || N19 === N15 || N19 === N16 || N19 === N17 || N19 === N18);
do {
N20 = Math.floor(Math.random() * 30) + 1;
} while(N20 === N1 || N20 === N2 || N20 === N3 || N20 === N4 || N20 === N5 || N20 === N6 || N20 === N7 || N20 === N8 || N20 === N9 || N20 === N10 || N20 === N11 || N20 === N12 || N20 === N13 || N20 === N14 || N20 === N15 || N20 === N16 || N20 === N17 || N20 === N18 || N20 === N19);
questions();
}
function questions() {
var Q = "Q";
var x1 = Q.concat(N1);
//var x1 = Q + N1;
var y1 = document.getElementById("Q1");
y1.innerHTML = x1;
var z1 = document.getElementById("1").getElementsByClassName("answers");
z1.innerHTML = A1;
console.log(x1);
}
最佳答案
您正在寻找的东西称为“数组”。
var questions = [
{
question: "5 x 10<sup>7</sup> = ?",
answer: "Find a calculator."
},
// ...
];
然后:
questions.sort(function() {return Math.random()-0.5;});
// imperfect shuffle, you'll need more code for a good one but this works decently
还有:
console.log(questions[0].question);
console.log(questions[0].answer);
关于Javascript - 如何让一个组合字母和数字的变量调用另一个变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47267841/
我有一个 html 格式的表单: 我需要得到 JavaScript在value input 字段执行,但只能通过表单的 submit .原因是页面是一个模板所以我不控制它(不能有
我管理的论坛是托管软件,因此我无法访问源代码,我只能向页面添加 JavaScript 来实现我需要完成的任务。 我正在尝试用超链接替换所有页面上某些文本关键字的第一个实例。我还根据国家/地区代码对这些
我正在使用 JS 打开新页面并将 HTML 代码写入其中,但是当我尝试使用 document.write() 在新页面中编写 JS 时功能不起作用。显然,一旦看到 ,主 JS 就会关闭。用于即将打开的
提问不是为了解决问题,提问是为了更好地理解系统 专家!我知道每当你将 javascript 代码输入 javascript 引擎时,它会立即由 javascript 引擎执行。由于没有看过Engi
我在一个文件夹中有两个 javascript 文件。我想将一个变量的 javascript 文件传递到另一个。我应该使用什么程序? 最佳答案 window.postMessage用于跨文档消息。使
我有一个练习,我需要输入两个输入并检查它们是否都等于一个。 如果是 console.log 正则 console.log false 我试过这样的事情: function isPositive(fir
我正在做一个Web应用程序,计划允许其他网站(客户端)在其页面上嵌入以下javascript: 我的网络应用程序位于 http://example.org 。 我不能假设客户端网站的页面有 JQue
目前我正在使用三个外部 JS 文件。 我喜欢将所有三个 JS 文件合而为一。 尽一切可能。我创建 aio.js 并在 aio.js 中 src="https://code.jquery.com/
我有例如像这样的数组: var myArray = []; var item1 = { start: '08:00', end: '09:30' } var item2 = {
所以我正在制作一个 Chrome 扩展,它使用我制作的一些 TamperMonkey 脚本。我想要一个“主”javascript 文件,您可以在其中包含并执行其他脚本。我很擅长使用以下行将其他 jav
我有 A、B html 和 A、B javascript 文件。 并且,如何将 A JavaScript 中使用的全局变量直接移动到 B JavaScript 中? 示例 JavaScript) va
我需要将以下整个代码放入名为 activate.js 的 JavaScript 中。你能告诉我怎么做吗? var int = new int({ seconds: 30, mark
我已经为我的 .net Web 应用程序创建了母版页 EXAMPLE1.Master。他们的 I 将值存储在 JavaScript 变量中。我想在另一个 JS 文件中检索该变量。 示例1.大师:-
是否有任何库可以用来转换这样的代码: function () { var a = 1; } 像这样的代码: function () { var a = 1; } 在我的浏览器中。因为我在 Gi
我收到语法缺失 ) 错误 $(document).ready(function changeText() { var p = document.getElementById('bidp
我正在制作进度条。它有一个标签。我想调整某个脚本完成的标签。在找到可能的解决方案的一些答案后,我想出了以下脚本。第一个启动并按预期工作。然而,第二个却没有。它出什么问题了?代码如下: HTML:
这里有一个很简单的问题,我简单的头脑无法回答:为什么我在外部库中加载时,下面的匿名和onload函数没有运行?我错过了一些非常非常基本的东西。 Library.js 只有一行:console.log(
我知道 javascript 是一种客户端语言,但如果实际代码中嵌入的 javascript 代码以某种方式与在控制台上运行的代码不同,我会尝试找到答案。让我用一个例子来解释它: 我想创建一个像 Mi
我如何将这个内联 javascript 更改为 Unobtrusive JavaScript? 谢谢! 感谢您的回答,但它不起作用。我的代码是: PHP js文件 document.getElem
我正在寻找将简单的 JavaScript 对象“转储”到动态生成的 JavaScript 源代码中的最优雅的方法。 目的:假设我们有 node.js 服务器生成 HTML。我们在服务器端有一个对象x。
我是一名优秀的程序员,十分优秀!