現在タイピングゲームをしているのですが、 正誤判定の実装が上手くいかず詰まっています。 正誤判定の実装は、 お題の文字とuserが記入した文字で1文字ずつ判定します。 タイピング中の文字と判定するのではなく、タイピング後記入欄に入っている文字と一文字づつ判断します。 例:お題 チョコ user ちょこ 入力ミス3文字

また、5問終わった時点で、文字のミス数によって下記の文が出るようにしたいです。 0文字:「完璧!」、 1から3文字:「おしい!」、 4から8文字:「まだまだです。」、 9文字以上:「頑張りましょう。」

現在、5問目が終わってボタンを押したときに結果を出したいので、タイマー処理ののif文で問題が6問目になったらという所にanswerを実行するという風にしてみたのですが、エラー文は出ないものの、コンソールには何も出なくなってしまい詰まっています。 アドバイスいただきたいです。

 <body>
    <p id="odai" style="width:500px; height:60px; padding-top:45px; border:solid 2px; text-align:center;"></p>
    <form name="form">
      <p style="text-indent:50px;">↓ここに入力</p>
      <input type="text" id="user" style="width:400px; height:30px; border:solid 2px; margin-left:50px; text-align:center;"></input>
      <br>
      <br>
      <input type="button" id="button" value="ok" onclick="testfunc()" style="width:60px; height:30px; margin-left:200px;"></input>
    </form>
    <p id="timer"></p>
      <p id="kekka"></p>
</body>
let box = [ //配列でお題を作成
  "キャンディ",
  "チョコ",
  "グミ",
  "クッキー",
  "スナック"
];

let odai = document.getElementById("odai"); //お題の取得
let user = document.getElementById("user"); //userの記入欄取得
let button = document.getElementById("button").value; //okボタンの取得
let kekka = document.getElementById("kekka"); //結果の取得
let timer = document.getElementById("timer"); //タイマーの取得
let time = 0; //タイム初期化
let countdown = null; //countdown初期化
let question_num = 0; //問題数をカウント
let answer = 0; //answerを初期化
let ansArray = []; //回答を入れる配列
let odaiArray = []; //お題を入れる配列

function testfunc() {
  
  //タイマー
  time = 11; //クリック時も、値を戻す   1秒誤差ありだから11秒
  if(countdown){
    clearInterval(countdown); //処理が二重にならないようボタン押下時に一旦タイマークリア
  }
  countdown = setInterval(function() { //setInterval()で1秒ずつ表示
  timer.textContent ='制限時間:' + --time + '秒'; //textContentで文字列と定数を組み合わせた文章を1秒おきに更新する
  for(let i = 0; i < 5;i++){
    if(time <= 0){
      time = 0; //カウントが終了したら、変数の値を戻す
      clearInterval(countdown); //0秒になったらタイマークリア
      user.value = ""; //時間切れの時は、user入力欄とお題を空欄にする
      odai.textContent = "";
    }else if(question_num == 6){ 
      clearInterval(countdown); //6問目になったらタイマークリア
      timer.textContent = ""; //タイマー表示を消す
 answer();
    }
  }
  }, 1000);

//お題ランダム表示
  let rnd = Math.floor(Math.random() * (box.length -1)); //boxの配列から1個少ない数を最大値とした乱数を作成    box.lengthはboxの中身分だけという意味
  tmp = box[rnd]; //変数tmpにboxの添字で[rnd]を入れる→ランダムに文章選択、文字列として利用できる
  box.splice(rnd,1); //rndから該当する配列をspliceで消去.表示
  odai.textContent = tmp; //tmpをお題欄に出力
  user.value = ""; //form内の要素をリセット
}

//正誤判定
  answer = () => { //全問入力した段階で、正解か判断する
    ansArray[question_num] = user.value; //回答を入れる配列内に問題数カウントを入れる  そこにuserのvalueを代入
    odaiArray[question_num] = odai.textContent; //お題を入れる配列内に問題数カウントを入れる  そこにodaiに出力されたものを代入
    question_num++; //問題数のカウントを一つずつ増やす
    let odai_num = odaiArray[question_num].split(""); //odaiArray[question_num]をsplitで文字を1文字ずつ分解し配列にする
    console.log(odai_num);
    let user_num = ansArray[question_num].split(""); //ansArray[question_num]をsplitで文字を1文字ずつ分解し配列にする
    console.log(user_num);
    if(odai_num == user_num){
    console.log("完璧!");
    }
  }