JavsScriptでゲーム順位を書き換える方法を探しています。
※自分でもネット上を駆け回って探しております。先に見つかれば報告しますのでご協力お願いします。
現在のJSは以下の通りです。
※やってみたこと
'00:20.00','zzz'を'30:00.00','zzz'に書き換えて再度ゲームしてみましたが、結果は30秒くらいにもかかわらず、書き換えられませんでした。
Js
1<script> 2var r=[ 3 ['00:05.00','abc'], 4 ['00:08.00','xyz'], 5 ['00:10.00','ijk'], 6 ['00:15.00','aaa'], 7 ['00:20.00','zzz'], 8 ]; 9const qs=[ 10 'Hello World', 11 'Good', 12 'I love JavaScript', 13 'This is MyApp', 14 'Welcome' 15 ]; 16 17window.addEventListener('DOMContentLoaded',()=>{ 18 document.querySelector('#start').addEventListener('click',e=>{ 19 const t1=e.target; 20 const t2=document.querySelector('#a'); 21 t1.disabled=true; 22 t2.disabled=false; 23 const name=prompt("your name?"); 24 if(name=="") name="noname"; 25 (async()=>{ 26 const qStr=qs[parseInt(Math.random()*qs.length)]; 27 const s=new Date().getTime(); 28 document.querySelector('#q span').textContent=qStr; 29 t2.value=""; 30 t2.focus(); 31 await new Promise(resolve=>{ 32 const timerId=setInterval(()=>{ 33 if(t2.value==qStr){ 34 clearInterval(timerId); 35 resolve(); 36 } 37 },10); 38 }); 39 const e=new Date().getTime(); 40 const diff=e-s; 41 const str=(10000+diff/1000).toString(); 42 const time=str.substr(1,2)+":"+ 43 str.substr(3,5); 44 r.push([time,name]); 45 r=await r.sort((x,y)=>x[0]>y[0]).splice(0,5); 46 alert(r.join("\n")); 47 t1.disabled=false; 48 t2.disabled=true; 49 })(); 50 }); 51}); 52 53</script> 54<input type="button" value="start" id="start"> 55<div id="q">Q:<span></span></div> 56A:<input type="text" id="a">
『書き換えられませんでした』とは具体的には何が起きていますか?
結果(実際に起きたこと)を書きましょう
https://teratail.com/help/question-tips#questionTips3-4-1
期待した処理結果を書きましょう
https://teratail.com/help/question-tips#questionTips3-4-3
ごめんなさい。
前の質問への回答がつづいているのでそちらを参考にしてください
それで解決しないようならこちらに回答します
同じ質問を繰り返し投稿するのは非推奨です(前の質問の続きなら前の質問のページで解決を試みてください)。
https://teratail.com/help/avoid-asking
回答1件
あなたの回答
tips
プレビュー