For a constantly increasing variable of cycle i, the condition i >= t is always true, since i = t already at the first iteration. In the meantime, this condition is true, the cycle will not stop. That is, it is infinite. To fix this, you can either change the condition to i <= t+5 , or the loop with the for counter can generally be replaced with a loop with a check of the while condition. In the second case, the code will be less with the same functionality. Now, regarding alert(++c); Why do you increase the value с before output? This makes no sense, since the values of с calculated for i at each iteration. According to the meaning of the problem, c = f (i), and you now have: c = f (i) +1. I am silent about the fact that alert does not make a table, it throws out to the user a pop-up window with a single value that blocks further program execution until it is closed. The formula for converting degrees to Fahrenheit to degrees Celsius is wrong. I sketched a correction for your task here:
<script type="text/javascript"> function temp() { var t = document.getElementById("t").value; //Делаем заголовок таблицы document.write("<table border=1>"); document.write("<tr><th>F</th><th>C</th></tr>"); for (var i = t; i <= +t+5; i++) { var c = (i - 32) * (5/9); document.write('<tr><td>'+i+'</td><td>'+c+'</td></tr>'); } document.write('</table>'); } </script> <form id='temp'> <input id="t" placeholder="Введите температуру по F"/> <button onclick='temp()'>Перевести температуру</button> </form>
I made a standard frame for the table and merged html and js into one file only in order to understand it faster, without being distracted by the separation of code by files and design. Redo as you need. Unary plus in the condition i<=+t+5 necessary for the correct type conversion. Without it, if, for example, t = 7, t + 5 = 75, and with it - t + 5 = 12.