试图根据答案计算总分';react.js/javascript中的s值

试图根据答案计算总分';react.js/javascript中的s值,javascript,java,arrays,json,reactjs,Javascript,Java,Arrays,Json,Reactjs,问题部分 class PersonalityQuiz extends React.Component { constructor() { super(); this.mc = []; this.mc.push([ { value: 1, text: "raphael" }, { value: 2, text: "donatello" },

问题部分

class PersonalityQuiz extends React.Component {
    constructor() {
        super();
        this.mc = [];
        this.mc.push([
            { value: 1, text: "raphael" },
            { value: 2, text: "donatello" },
            { value: 3, text: "leonardo" },
            { value: 4, text: "michaelangelo" }
        ]);
        this.mc.push([
            { value: 1, text: "fluttershy" },
            { value: 2, text: "pinkie pie" },
            { value: 3, text: "rainbow dash" },
            { value: 4, text: "rarity" }
        ]);
        this.state = {
            score: 0
        };
  }
基于答案的复习部分总分应增加答案值(从1增加到4)。之后没有多少代码

    handleShowScore = e => {
        let a = document.querySelectorAll("select");
        let newScore = 0;
        for (let i = 0; i < a.length; i++) {
      var newScore = newScore + a[i].value;
    }
    
        this.setState({
            score: newScore
        });
  };
handleShowScore=e=>{
设a=document.querySelectorAll(“select”);
让newScore=0;
for(设i=0;i
您正在循环中创建另一个
newScore
变量,因为
var
let
都创建了一个新变量。所以原版永远不会更新。更改
var newScore=newScore+a[i]。值
to
newScore=newScore+a[i]。值或使用速记增量
newScore+=a[i]。值

什么是计数?你需要显示更多的代码。这基本上就是全部代码。稍微更新一下,让它更有意义?谢谢你的调查非常感谢先生!他真是个魅力人物!刚刚更新到newScore=newScore+parseInt(a[i].value)以获取结果的总和。干杯