【发布时间】:2014-12-10 00:38:15
【问题描述】:
我是一个 JavaScript 新手。我一直在努力完成这项任务,但就是看不出我的错误在哪里,而且它应该在午夜前完成。任何帮助,将不胜感激!这些是说明:
创建以重定向到已完成表格的按钮开头的网页。 生成的表格是一个 3 X 4 的表格,每个单元格都填满了一个数学问题。 数学问题将使用 1 到 20 之间的随机数。 这些问题将使用以下 4 种操作之一:加法、减法、 乘法或除法也是随机生成的。我必须使用以下函数:
函数 buildIt()
函数 buildTable(rows, cols)
函数 randOne()
函数 randTwo()
!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>Random Math Table Generator</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type = "text/javascript">
function buildIt()
{
//function to call buildTable setting the values for the //rows and columns the table
var rows; var cols; var i; var j;
buildTable(rows, cols);
}
function buildTable(rows, cols)
{
//function to build actual table
//include for loop in which next two functions are called
document.write("<div id='content'><p> </p>");
document.write("<table width = '60%' border = '1' align = 'center' cellpadding = '5' cellspacing = '5'>");
ranNum = (rows + 1) * (cols + 1);
for (i = 0; i < rows; i++)
{
document.write("<tr>");
for (j = 0; j < cols; j++)
{
document.write("</tr>");
}
document.write("</table> </div>");
}
function randOne(min, max)
{
//function to generate random number between 1 and 20
var randNumOne = return Math.floor(Math.random() * 21);
var randNumTwo = return Math.floor(Math.random() * 21);
}
function randTwo()
{
//function to generate the specified operations randomly
var cellContents;
switch(randOp){
case "+": answerNumb = randNumOne + randNumTwo; break;
case "-": answerNumb = randNumOne - randNumTwo; break;
case "÷": answerNumb = randNumOne / randNumTwo; break;
case "x": answerNumb = randNumOne * randNumTwo; break;
}
cellContents = randNumOne + operation + randNumTwo;
}
}
</script>
</head>
<body>
<div id="container">
<h1 id="logo">Table Builder</h1>
<p><input type ="button" onclick="buildIt()" value = "Build a table"></p>
</div>
</body>
</html>
【问题讨论】:
-
F12 键通常会在大多数浏览器中打开开发者控制台。从那里开始。
标签: javascript math button random onclick