下記コードのupdateTime関数内の変数「accuration」において、toFixedメソッドを通しているのですが、適用されなかった為、原因が分からずご質問させて頂きました。
'use strict'; { let words = ['blue','apple','sky','middle','set']; let word; let isPlaying = false; let loc = 0; let target; let letter_count = 0; let miss_count = 0; let miss_label; let letter_label; let timeLimit; timeLimit = 3 * 1000; let start_time; let time_label = document.getElementById('time_left'); let accuracy window.addEventListener('click',() => { if(isPlaying == true){ return; } function updateTime(){ let time_left = start_time + timeLimit - Date.now(); time_label.textContent = (time_left / 1000) .toFixed(2); const time_out_id = setTimeout(() => { updateTime(); },10); if(time_left < 0){ isPlaying = false; clearTimeout(time_out_id); if(letter_count == 0 && miss_count == 0){ accuracy = 0; }else if(miss_count == 0){ accuracy = 100 }else if(letter_count == 0){ accuracy = 0; }else{ accuracy = (miss_count / letter_count) * 100; accuracy.toFixed(2); console.log(accuracy); } console.log(miss_count); console.log(letter_count); window.alert(letter_count + 'letters,' + miss_count + 'misses, ' + accuracy + '%accuracy!'); } } isPlaying = true; letter_label = document.getElementById('Letter_label'); miss_label = document.getElementById('Letter_miss_label'); target = document.getElementById('top_word'); word = words[Math.floor(Math.random() * words.length)]; target.textContent = word; start_time = Date.now(); updateTime(); }); window.addEventListener('keyup', e => { if(isPlaying === true){ let placeholder = ''; if(e.key == word[loc]){ loc++; letter_count += 1; console.log(letter_count); letter_label.textContent = letter_count; for(let i = 0; i < loc; i++){ placeholder += '_'; } console.log(word.substring(loc)); console.log(placeholder); target.textContent = placeholder + word.substring(loc); }else{ miss_count++; miss_label.textContent = miss_count; } if(loc == word.length){ word = words[Math.floor(Math.random() * words.length)]; target.textContent = word; loc = 0; } } }); }
updateTimeメソッド内のaccurationが「33.33333」であったとしても、toFixedメソッドを通した場合でも、変わらず、console.log(accuracy);の出力結果は変わらず、「33.33333」になってしまいます。
原因究明の為、ご助言頂けましたら幸いです。
そもそもご自身は原因究明のため何をされたのでしょうか。
コメントから、あまり自身が提示されたコードをちゃんと理解して書いているように思えません。

回答2件
あなたの回答
tips
プレビュー