Javascript 类型编号不能分配给类型字符串

Javascript 类型编号不能分配给类型字符串,javascript,Javascript,我正在做一个增量游戏,遇到了一个错误。。。。。。。。。类型“number”不可分配给所有文档上的类型“string”。getElement var vegetas = 0; var gohan = 0; function vegetaClick(number) { vegetas = vegetas + number; document.getElementById("Textout").innerHTML = vegetas; }; function buyGohan()

我正在做一个增量游戏,遇到了一个错误。。。。。。。。。类型“number”不可分配给所有文档上的类型“string”。getElement

var vegetas = 0;
var gohan = 0;

function vegetaClick(number) {
    vegetas = vegetas + number;
    document.getElementById("Textout").innerHTML = vegetas;
};

function buyGohan() {
    var gohanCost = Math.floor(10 * Math.pow(1.1,gohan));     
    if(vegetas >= gohanCost){                                   
        gohan = gohan + 1;                                   
        vegetas = vegetas - gohanCost;                         
        document.getElementById("gohan").innerHTML = gohan;  
        document.getElementById('vegetas').innerHTML = vegetas;  
        document.getElementById("gohan").style.display= "block";
    };
    var nextCost = Math.floor(10 * Math.pow(1.1,gohan));       
    document.getElementById('gohanCost').innerHTML = nextCost;  
};

强制将
nextCost
强制转换为字符串值:

document.getElementById('gohanCost').innerHTML = "" + nextCost;  


Try-innerHTML返回字符串,但是
vegetas
gohan
都是int。您在哪个浏览器上测试?至少在chrome中给innerHTML分配一个数字是可以的……给
innerHTML
分配一个数值对我来说很好。
// Note, no new
document.getElementById('gohanCost').innerHTML = String(nextCost);