|
<!doctype html> |
|
|
|
|
|
<meta charset= "utf-8" > |
|
<title> print Diamond </title> |
|
<script type= "text/javascript" > |
|
var num = prompt ("Please enter the number of lines printed:"); |
|
for (var i=1;i<=num;i++)//determines the number of rows to output |
|
{ |
|
for (var j=1;j<=num-i;j++)//determines the number of spaces at the beginning of each line |
|
{ |
|
document.write ("the"); |
|
} |
|
for (var k=1;k<=2*i-1;k++)//Determine the * number of each line |
|
{ |
|
document.write ("*"); |
|
} |
|
document.write ("</br>"); |
|
} |
|
<!--/* Output the lower half of the diamond */--> |
|
for (var i=1;i<=num-1;i++)//determines the number of rows to output |
|
{ |
|
for (var j=1;j<=i;j++)//determines the number of spaces at the beginning of each line |
|
{ |
|
document.write ("the"); |
|
} |
|
for (var k=1;k<=2*num-1-2*i;k++)//Determine the * number of each line |
|
{ |
|
document.write ("*"); |
|
} |
|
document.write ("</br>"); |
|
} |
|
</script> |
|
|
|
<body> |
|
</body> |
|
|
JavaScript print Diamond input print line number automatic printing