Javascript 如何用html制作计算参考表?

Javascript 如何用html制作计算参考表?,javascript,html,Javascript,Html,我是html新手,我需要帮助在html中创建计算参考表。它应该是这样的: 我有以下代码: <html> <head> <script language="javascript" type="text/javascript"> function squareIt(x){ document.write (x * x); } function divideIt(x){ document.write

我是html新手,我需要帮助在html中创建计算参考表。它应该是这样的:

我有以下代码:

<html>
<head>


    <script language="javascript" type="text/javascript">
    function squareIt(x){
        document.write (x * x);
    }
    function divideIt(x){
        document.write(1 / x);
    }
    function sqrtIt(x){
        document.write(Math.sqrt(x));
    }
    document.write("<table>");
        for (var a=1; a < 6; a++) {
            document.write("<tr>" + a);
        for (var b=1; b < 2; b++) {
            document.write("<td>"+squareIt(a)+"</td>");
            document.write("<td>"+divideIt(a)+"</td>");
            document.write("<td>"+sqrtIt(a)+"</td>");
        }
        document.write("</tr>");
        }
    document.write("</table>");
    </script>
</head>

函数平方(x){
document.write(x*x);
}
函数divideIt(x){
文件。书写(1/x);
}
函数sqrtIt(x){
编写(Math.sqrt(x));
}
文件。填写(“”);
对于(变量a=1;a<6;a++){
文件。填写(“+a”);
对于(变量b=1;b<2;b++){
文件。写(“+squareIt(a)+”);
文件。写(“+”除(a)+”);
写(“+sqrtIt(a)+”);
}
文件。填写(“”);
}
文件。填写(“”);

我无法根据图片将这些值放入表中。有什么建议吗


谢谢大家!

您的函数必须是
return
value,才能在
文档中使用。wrire
或从文档中调用函数。write 我编辑你的脚本

函数平方(x){
返回(x*x);
}
函数divideIt(x){
回报率(1/x);
}
函数sqrtIt(x){
返回(数学sqrt(x));
}
文件。填写(“”);
文件写入(“xx21/xsqrt(x)”)
对于(变量a=1;a<6;a++){
文件。填写(“”);
文件。写入(“+a+”)
文件。写(“+squareIt(a)+”);
文件。写(“+”除(a)+”);
写(“+sqrtIt(a)+”);
文件。填写(“”);
}

桌子{
宽度:400px;
}
表,td{
边框:1px纯黑;
}
运输署{
宽度:25%;
文本对齐:居中;
}

您编写的代码中的一个设计错误是嵌套循环是错误的解决方案。此任务中没有“y”。只有x。其他一切都是已知的,不适合用第二个循环处理

因此,让你的一个也是唯一一个循环来迭代X的各种值,然后在循环中对X的三种用法(以及它们所需要的所有其他用法)进行专门编码

意思是:

   // Build HTML for start of table.
   // For loop through x values.
      // start of a row
      // cell for x value
      // cell for x^2
      // cell for 1/x
      // cell for sqrt(x)
      // end of row
   // end of loop
   // end of table HTML

祝你好运

在您的情况下,函数应该返回一些东西,而不是。