小编Sar*_*hen的帖子

未捕获的类型错误:无法读取未定义的属性“toFixed”

我知道其他人也抛出了这个错误,但我认为我有某种语法问题导致我发生这种情况。如果您能找到它,我将不胜感激。我是 JavaScript 新手,已经盯着这个简单的程序一个小时了。

这是 JavaScript:

"use strict";
var $ = function(id) {
    return document.getElementById(id);
};

var calculateFV = function(investmentAmount, interestRate, yearsAmount) {
    var futureValue;

    //get the future value after the amount of years entered
    for (var i = 1; i <= yearsAmount; i++ ) {
        var interest = futureValue * interestRate / 100;
        futureValue = futureValue + interest;
    }

    return futureValue.toFixed(2);
};

var processEntries = function(investmentAmount, interestRate, yearsAmount) {
    var investment = investmentAmount;
    var interest = interestRate;
    var years = …
Run Code Online (Sandbox Code Playgroud)

javascript onclick syntax-error tofixed

2
推荐指数
2
解决办法
2万
查看次数

为什么这个javaclass会出现这种异常?

我从一个网站上获得了这个代码以适应其他用途,但是当我在Netbeans上尝试它时,它一直给我一些问题.我看了看它看起来很稳固,但我显然不是......例外是:

"'{'预期"和"类,界面或枚举预期."

我检查了所有括号和括号,我无法弄清楚它有什么问题.

public class Coin() 
{
    private String sideUp;

    /**
    * Default constructor
    */
    public Coin() 
    {
    // initialize sideUp
        toss();
    }

    /**
    * This method will simulate the tossing of a coin. It should set 
    * the   
    * sideUp field to either "heads" or "tails".
    */
    public void toss() 
    {

        Random rand = new Random();

        // Get a random value, 0 or 1.
        int value = rand.nextInt(2);

        if (value == 0) 
        {
            this.sideUp = "heads";
        } 
        else 
        { …
Run Code Online (Sandbox Code Playgroud)

java class

1
推荐指数
1
解决办法
37
查看次数

标签 统计

class ×1

java ×1

javascript ×1

onclick ×1

syntax-error ×1

tofixed ×1