発生している問題・エラーメッセージ
素人質問で申し訳ないです。
下記のコードのrecalc(16~23行)に引数を与えなくても、goal(14行)の値を取得して29行目の実行の際にcountdown関数で現在時刻とgoaLとの差分を計算できるのはなぜですか。
17行目のgoalは仮引数と考えると動かないのでは?という考えです。
該当のソースコード
JavaScript
1function countdown(due) { 2 const now = new Date(); 3 4 const rest = due.getTime() - now.getTime(); 5 const sec = Math.floor(rest/1000)%60; 6 const min = Math.floor(rest/1000/60)%60; 7 const hour = Math.floor(rest/1000/60/60)%24; 8 const day = Math.floor(rest/1000/60/60/24); 9 const count = [day,hour,min,sec]; 10 11 return count; 12 } 13 14 let goal = new Date(2025,4,3); 15 16function recalc() { 17 const counter = countdown(goal); 18 document.getElementById('day').textContent = counter[0] 19 document.getElementById('hour').textContent = counter[1] 20 document.getElementById('min').textContent = String(counter[2]).padStart(2,'0'); 21 document.getElementById('sec').textContent = String(counter[3]).padStart(2,'0'); 22 refresh(); 23 } 24 25function refresh() { 26 setTimeout(recalc,1000); 27 } 28 29 recalc(); 30 31

回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。