我想要Javascript中的总分和评论(基于总分)

我想要Javascript中的总分和评论(基于总分),javascript,Javascript,在下面的代码中,我试图计算总分,如果总分小于10,它将显示一些注释,其他注释。所以基本上我需要总分和评论 在尝试时,如果我使用calculateTotal函数和DeleteGetComment函数,它会工作,反之亦然。但当我同时使用这两个函数时,什么都不会出现。这是我的密码 function calculateTotal() { //Here we get the total Score by calling our function //Each function return

在下面的代码中,我试图计算总分,如果总分小于10,它将显示一些注释,其他注释。所以基本上我需要总分和评论

在尝试时,如果我使用calculateTotal函数和DeleteGetComment函数,它会工作,反之亦然。但当我同时使用这两个函数时,什么都不会出现。这是我的密码

function calculateTotal()
{
    //Here we get the total Score by calling our function
    //Each function returns a number so by calling them we add the values they return together
    var Scoring = getScore() + getScore1() + getScore2() + getScore3() + getScore4();

    //display the result
    var divobj = document.getElementById('totalScore');
    divobj.style.display='block';
    divobj.innerHTML = "Total Score for the selected answer "+Scoring;
    getComment(Scoring);
}

getComment(Scoring)
if (totalScore == 10) {
    document.getElementById("displaycomment").innerHTML = "Excellent Result"+Scoring;
}
else {
    document.getElementById("displaycomment").innerHTML = "See the guidebook"+Scoring;
}

尝试同样的objet方法

复制到html并运行示例时,代码段不起作用

var a = 2;

function getScore() {
    return a;
}

function getScore1() {
    return a;
}

function getScore2() {
    return a;
}

function getScore3() {
    return a;
}

function getScore4() {
    return a;
}

var calcClass = new function() {
    this.Scoring = function() {
        return getScore() + getScore1() + getScore2() + getScore3() + getScore4();
    }

    this.divobj = document.getElementById('totalScore');
    this.divobj.style.display = 'block';
    this.divobj.innerHTML = "Total Score for the selected answer " + this.Scoring();

    this.getComment = function() {
        if (this.Scoring() == 10) {
            document.getElementById("displaycomment").innerHTML = "Excellent Result " + this.Scoring();
        } else {
            document.getElementById("displaycomment").innerHTML = "See the guidebook " + this.Scoring();
        }
    }
}
alert("total " + calcClass.Scoring());
calcClass.getComment();

//try to console see and check result
//a = 3;
//calcClass.getComment();
//alert("total " + calcClass.Scoring());




<div class="scoregroup">total score <div id="totalScore"></div></div>
<div class="scoregroup">display comment <div id="displaycomment"></div>      </div>
var a=2;
函数getScore(){
返回a;
}
函数getScore1(){
返回a;
}
函数getScore2(){
返回a;
}
函数getScore3(){
返回a;
}
函数getScore4(){
返回a;
}
var calcClass=新函数(){
this.Scoring=function(){
返回getScore()+getScore1()+getScore2()+getScore3()+getScore4();
}
this.divobj=document.getElementById('totalScore');
this.divobj.style.display='block';
this.divobj.innerHTML=“所选答案的总分”+this.Scoring();
this.getComment=函数(){
if(this.Scoring()==10){
document.getElementById(“displaycomment”).innerHTML=“优秀结果”+this.Scoring();
}否则{
document.getElementById(“displaycomment”).innerHTML=“参见指南”+this.Scoring();
}
}
}
警报(“总计”+计算等级评分());
getComment();
//尝试查看并检查结果
//a=3;
//getComment();
//警报(“总计”+计算等级评分());
总分
显示注释

不,那不是你的代码,那是你代码的图像。您是否打开控制台查看是否收到错误消息?另外,在您的图像中,getComment()函数并没有被{…}包围——请放入卷发!哇!现在这是一个更糟糕的代码图像。尽管如此,getComment实际上并不是一个函数。所以,是的。尝试编辑您的问题,并将您的代码示例放在代码块中:。这将使其他人更容易回答您的问题。在
getComment()
中,您比较不存在的“totalScore”,它应该是“Scoring”。此外,您还比较了“等于10”,这只有在10是最大可能分数时才是正确的?为什么不使用这个示例代码段?但是为什么要运行普通页面。。。