以 ASCII 模式显示字符

Displaying characters in pattern from ASCII

就像标题所说的那样,我们想要以 ASCII 值的模式显示一组字符。我们想出了这个代码,但它不起作用...

for (var i = 1; i < 7; i++) {
            for (var j = 46; j < i + 1; j++) {
                document.write(String.fromCharCode(j));
            }
            document.write("<br>");
        }

        for(var k = 8; k > 1; k--) {
            for(var l = 97; l < k - 1; l++){
            document.write(String.fromCharCode(l));
            }
            document.write("<br>");
        }

输出应该是这样的:

一个

AB

ABC

ABCD

ABCDE

ABCDEF

ABCDEFG

ABCDEFGH

ABCDEFGHI

abcdefgh

abcdefg

abcdef

abcde

abcd

abc

ab

一个

试试这个..

for (var i = 1; i < 10; i++) {
            for (var j = 65; j < 65+i; j++) {
                document.write(String.fromCharCode(j));

            }
            document.write("<br>");
        }

        for(var k = 10; k > 1; k--) {

            for(var l = 97; l < 96+k; l++){

            document.write(String.fromCharCode(l));
            }
            document.write("<br>");
        }

结果:

A
AB
ABC
ABCD
ABCDE
ABCDEF
ABCDEFG
ABCDEFGH
ABCDEFGHI
abcdefghi
abcdefgh
abcdefg
abcdef
abcde
abcd
abc
ab
a