Home > Web Front-end > JS Tutorial > body text

js implements printing a colored diamond (code)

不言
Release: 2018-08-16 10:51:42
Original
2003 people have browsed it

The content of this article is about the js implementation of printing a colored diamond (code). It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>weirdo</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        .lx {
            text-align: center;
            letter-spacing: 5px;
            margin: 20px;
        }
    </style>
</head>
<body>
<div>
    <script>
        function cl() {
            var c = '0123456789abcdef';
            var cc = '#';
            cc += c.charAt(Math.round(Math.random() * (c.length - 1)));
            cc += c.charAt(Math.round(Math.random() * (c.length - 1)));
            cc += c.charAt(Math.round(Math.random() * (c.length - 1)));
            cc += c.charAt(Math.round(Math.random() * (c.length - 1)));
            cc += c.charAt(Math.round(Math.random() * (c.length - 1)));
            cc += c.charAt(Math.round(Math.random() * (c.length - 1)));
            return cc;
        }

        function ling(num) {
            for (var i = 1; i <= num; i += 2) {
                document.write(&#39;<p>');
                for (var j = 1; j <= i; j++) {
                    document.write(&#39;<span style="color:&#39; + cl() + &#39;">*</span>');
                }
                document.write('</p>');
            }
            for (var i = num; i >= 1; i -= 2) {
                document.write('<p>');
                for (var j = 1; j <= i; j++) {
                    document.write(&#39;<span style="color:&#39; + cl() + &#39;">*</span>');
                }
                document.write('</p>');
            }
        }

        ling(15);
    </script>
</div>
</body>
</html>
Copy after login

Related recommendations:

How to implement lazy loading of images in js? js method code to implement delayed loading of images

js time conversion: timestamp to time string (code)

Verification in js Summary of digital methods

The above is the detailed content of js implements printing a colored diamond (code). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template