Урок 2

<-- Start of ex2.1\2.1.html --> 
<!doctype html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>Из дюймов в сантиметры</title>
    </head>
    <body>
        <h1>Пересчет величин</h1>
        <script type="text/javascript">
            const ins = window.prompt('Величина в дюймах', 0);
            const cents = ins * 2.54;
            window.document.write('<p>', cents, '</p>');
        </script>
    </body>
</html>
 
<-- End of ex2.1\2.1.html --> 
 
<-- Start of ex2.2\2.1.html --> 
<!doctype html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>Из дюймов в сантиметры</title>
    </head>
    <body>
        <h1>Пересчет величин</h1>
        <script type="text/javascript">
            const ins = window.prompt('Величина в дюймах', 0);
            let cents = 'Величина не была введена';
            if (ins != null)
                cents = ins * 2.54;
            window.document.write('<p>', cents, '</p>');
        </script>
    </body>
</html>
 
<-- End of ex2.2\2.1.html --> 
 
<-- Start of ex2.3\2.1.html --> 
<!doctype html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>Из дюймов в сантиметры</title>
    </head>
    <body>
        <h1>Пересчет величин</h1>
        <script type="text/javascript">
            const ins = window.prompt('Величина в дюймах', 0);
            if (ins == null)
                window.document.write('<p>Величина не была введена</p>');
            else {
                const cents = ins * 2.54;
                window.document.write('<p>', cents, '</p>');
            }
        </script>
    </body>
</html>
 
<-- End of ex2.3\2.1.html --> 
 
<-- Start of ex2.5\2.5.html --> 
<!doctype html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>Квадратные корни</title>
    </head>
    <body>
        <h1>Квадратные корни от 1 до 10</h1>
        <table>
        <script type="text/javascript">
            let i;
            for (i = 1; i <= 10; ++i) {
                window.document.write('<tr><td>', i, '</td>');
                window.document.write('<td>', Math.sqrt(i), '</td></tr>');
            }
        </script>
        </table>
    </body>
</html>
 
<-- End of ex2.5\2.5.html --> 
 
<-- Start of s2.11\2.1.html --> 
<!doctype html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>Из дюймов в сантиметры</title>
    </head>
    <body>
        <h1>Пересчет величин</h1>
        <script type="text/javascript">
            const ins = window.prompt('Величина в дюймах', 0);
            if (ins == null)
                window.document.write('<p>Величина не была введена</p>');
            else {
                let s;
                switch(Math.floor(ins)) {
                    case 1:
                        s = 'дюйм';
                        break;
                    case 2:
                    case 3:
                    case 4:
                        s = 'дюйма';
                        break;
                    default:
                        s = 'дюймов';
                }
                window.document.write('<p>', ins, ' ',s , '</p>');
                const cents = ins * 2.54;
                window.document.write('<p>', cents, ' см.</p>');
            }
        </script>
    </body>
</html>
 
<-- End of s2.11\2.1.html --> 
 
<-- Start of s2.11\2.9.1.html --> 
<!doctype html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>Квадратные корни</title>
    </head>
    <body>
        <h1>Квадратные корни от 10 до 200</h1>
        <table>
        <script type="text/javascript">
            let i;
            for (i = 10; i <= 200; i += 10) {
                window.document.write('<tr><td>', i, '</td>');
                window.document.write('<td>', Math.sqrt(i), '</td></tr>');
            }
        </script>
        </table>
    </body>
</html>
 
<-- End of s2.11\2.9.1.html --> 
 
<-- Start of s2.11\2.9.2.html --> 
<!doctype html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>Среднее арифметическое</title>
    </head>
    <body>
        <h1>Среднее арифметическое</h1>
        <p>
        <script type="text/javascript">
            let i, sum = 0, count = 0;
            while (true) {
                i = +window.prompt('Очередное число', 0);
                if (i == 0)
                    break;
                else {
                    ++count;
                    sum += i;
                }
            }
            sum /= count;
            window.document.write('Среднее арифметическое: ', sum);
        </script>
        </p>
    </body>
</html>
 
<-- End of s2.11\2.9.2.html -->