简体   繁体   English

尝试在 javascript 和 html 中制作时间表计算器

[英]Trying to make times table calculator in javascript and html

I am trying to make a calculator in JavaScript and html so that when a number is entered and calculate is pressed the times table for that number will be displayed however nothing is being outputted.我正在尝试用 JavaScript 和 html 制作一个计算器,这样当输入一个数字并按下计算时,将显示该数字的时间表,但没有输出任何内容。 Here is my code any help is greatly appreciated.这是我的代码,非常感谢任何帮助。 Many thanks for looking.非常感谢您的关注。

<html>

<head>
    <title> Javascript</title>
</head>

<body>
    <script>
        var i = 1;
        var result;
        var results = new Array();


        function calculate_this() {
            var input = document.getElementById("input").value;

            do {
                var result = input * i;
                results.push(result);
                i = i + 1;
            }
            while (i < 12);
            document.getElementById("output").innerHTML = results.string();

        }
    </script>

    <H1>Calculator</H1>
    <input type="text" id="input">
    <input type=button value="Calculate" onClick="calculate_this()">
    <br>
    <H2 id="output"></H2>


</body>

</html>

document.getElementById("output").innerHTML = results.toString();

.string()不是数组方法,所以它抛出了一个错误。

There is no Array method string() ... There is a method toString .没有Array方法string() ... 有一个方法toString So this line:所以这一行:

document.getElementById("output").innerHTML = results.string();

can be updated to this:可以更新为:

document.getElementById("output").innerHTML = results.toString();

 var i = 1; var result; var results = new Array(); function calculate_this() { var input = document.getElementById("input").value; do { var result = input * i; results.push(result); i = i + 1; } while (i < 12); document.getElementById("output").innerHTML = results.toString(); }
 <H1>Calculator</H1> <input type="text" id="input"> <input type=button value="Calculate" onClick="calculate_this()"> <br> <H2 id="output"></H2>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 内置计算器的HTML / Javascript表 - Html/Javascript table with built in calculator Javascript:时间表,将第一个单元格设为空白,尝试获取此输出 - Javascript: Times table, make first cell blank, trying to get this output 我在尝试使用html和Javascript制作计算器时陷入困境 - I'm getting stuck while trying to make a calculator using html and Javascript 我正在尝试使用HTML Javascript制作分数计算器,我需要简化分数该怎么做? - I am trying to make a Fraction Calculator in HTML Javascript, I need to simplify the fraction how can I do this? 尝试用JavaScript编码计算器 - Trying to code a calculator in JavaScript 我正在尝试使用 AddEventListener 和 QuerySelector 制作一个简单的 Javascript 计算器 - I'm trying to make a simple Javascript calculator with AddEventListener and QuerySelector 我正在尝试用 Javascript 制作一个计算器。 但它以某种方式不起作用 - I am trying to make a calculator in Javascript. But it is not working somehow 试图用 javascript 做一个计算器,但没有给出任何结果 - Trying to make a calculator with javascript but doesn't give any results 如何使用html和javascript制作一种计算器? - How do i make a sort of calculator using html and javascript? 需要使用 HTML/CSS 和 Javascript 从头开始制作计算器 - Need to make Calculator using HTML/CSS and Javascript from Scratch
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM