Javascript,以秒为单位-每次添加一个点

Javascript,以秒为单位-每次添加一个点,javascript,html,project,Javascript,Html,Project,所以我正在做我的一个项目,我想得到一些帮助 我希望javascript能够以秒为单位计数,每秒钟它都会添加一个预设的点数 var total_points = 0 var points_per_click = 1 var points_per_second = 0 function points_per_second() { docuement.getElementById("current_points").innerHTML("Current Points: " + total_point

所以我正在做我的一个项目,我想得到一些帮助

我希望javascript能够以秒为单位计数,每秒钟它都会添加一个预设的点数

var total_points = 0
var points_per_click = 1
var points_per_second = 0

function points_per_second() {
docuement.getElementById("current_points").innerHTML("Current Points: " + total_points);
//insert here?
}

我还希望每秒的积分能够添加到总积分变量中。谢谢

docuement
拼写为“document”
。innerHTML
不是函数调用(将其设置为变量)&变量和函数共享同一名称空间,不设置变量
每秒点数
,然后声明同名函数

一旦对语法错误进行了排序,您可能正在查找


那么你的问题是什么?
var total_points = 0;
var points_per_click = 1;
var points_per_second = 2;

function update_display(){
    var el = document.getElementById("current_points");
    el.innerHTML = "Current Points: " + total_points;
    //insert here? ... No
}

var ticker = setInterval(function(){
    total_points += points_per_second; 
    // ... or whatever your intended logic
    update_display();
}, 1000);