1kmのタイムを入力して、42.195kmのタイムを予想したいです。
1分0秒と入力すると、明らかに違う答えが出るのですが、どこが間違っているのでしょうか? Math.floorがうまくいっていない気がします。よろしくお願いいたします。
<!doctype html> <html> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width,initial-scale=1"> <title>テンプレート</title> <link href="../../_common/images/favicon.ico" rel="shortcut icon"> <link href="https://fonts.googleapis.com/css?family=M+PLUS+1p:400,500" rel="stylesheet"> <link href="../../_common/css/style.css" rel="stylesheet"> <style> #form{ display: flex; } </style> </head> <body> <header> <div class="container"> <h1>タイトル</h1> <h2>サブタイトル</h2> </div><!-- /.container --> </header> <main> <div class="container"> <section> <p>1kmのタイム</p> <form action="#" id="form"> <input type="number" id="min" name="inputMin" min="0" max="10"> <p>分</p> <input type="number" id="sec" name="inputSec" min="0" max="60"> <p>秒</p> <form action="#" id="form"> <input type="submit" value ="計算"> </form> <p>予測タイム</p> <span id = "output"></span> </section> </div><!-- /.container --> </main> <footer> <div class="container"> <p>JavaScript Samples</p> </div><!-- /.container --> </footer> <script> 'use strict' //ボタンを押した後の処理 document.getElementById('form').onsubmit = function (event){ event.preventDefault(); let min1 = document.getElementById('form').inputMin.value; let sec1 = document.getElementById('form').inputSec.value; let allSecond = (min1 * 60) + sec1; let timeOfFull = 42.195 * allSecond; let hour2 = Math.floor(timeOfFull/3600); let min2 = Math.floor((timeOfFull % 3600)/60); let sec2 = timeOfFull % 60; document.getElementById('output').textContent = `${hour2}時間${min2}分${sec2}秒`; } </script> </body> </html>
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/06/12 09:19