我在这里声明了一个变量:
I have a variable declared here:
var quizScore = 0;我想在每次 correctAnswer()时添加一个数字函数运行:
function correctAnswer(){ quizScore+1; console.log ( 'correct answer selected: quizscore = ' + quizScore ); }我添加了一个用于调试的控制台日志。它工作正常,因此正在调用该函数,但它没有添加分数。我需要将其解析为整数吗?我无法弄清楚+1需要正常工作。
I added a console log for debugging. It works, so the function is being called, but it is not adding the score. Do I need to parse this to an integer? I can't work out what the +1 needs to be to work correctly.
你可以去这里,你会看到点击问题1的Lightning Bolt在控制台中显示正确答案,但是没有添加到得分变量。
You can go here and you will see that clicking "Lightning Bolt" for question 1 shows "correct answer" in the console, but doesn't add to the score variable.
推荐答案这样做:
function correctAnswer(){ console.log ( 'correct answer selected: quizscore = ' + (++quizScore) ); }您只需要将+1分配给quizScore变量。这可能是添加1并以一行显示的最快方式
You just need to assign the +1 to quizScore variable. This may be the fastest way to add 1 and display it in one line
更多推荐
将整数添加到JavaScript变量
发布评论