当前位置:网站首页>使用JS在浏览器中打印菱形
使用JS在浏览器中打印菱形
2022-08-04 05:31:00 【look up at the stars】
打印菱形:(当页面加载完毕时根据弹出的提示信息输入想要打印的菱形的行数。注释:输入的数字为菱形的行数一半+1)
例如下图即输入6以后打印的图形。
示例代码:
<script type="text/javascript">
var num=prompt("请输入打印的行数:","");
for (var i=1;i<=num;i++){
document.write(" ");
for (var k=num;k>=i;k--){
document.writeln(" ");
}
for (var j=1;j<=2*i-1;j++){
if(j%2==0){
document.writeln(" ");
}else{
document.writeln("*");
}
}
document.write("<br/>");
}
for (var i=num-1;i>=1;i--){
document.write(" ");
for (var k=num;k>=i;k--){
document.writeln(" ");
}
for (var j=1;j<=2*i-1;j++){
if(j%2==0){
document.writeln(" ");
}else{
document.writeln("*");
}
}
document.write("<br/>");
}
</script>
边栏推荐
猜你喜欢

Amazon Cloud Technology Build On-Amazon Neptune's Knowledge Graph-Based Recommendation Model Building Experience

Amazon Cloud Technology Build On 2022 - AIot Season 2 IoT Special Experiment Experience

Pytest common plug-in

第二章 STA相关概念

MNIST手写数字识别 —— ResNet-经典卷积神经网络

C语言结构体(必须掌握版)

arm-3-中断体系结构

makefile基础学习

集合---ArrayList的底层

集合--LinkedList
随机推荐
jdbc:mysql://localhost:3306/student?serverTimezone=CTT&useUnicode=true&characterEncoding=utf-8时报错
[CV-Learning] Linear Classifier (SVM Basics)
Rules.make - suitable for viewing in edit mode
腾讯、网易纷纷出手,火到出圈的元宇宙到底是个啥?
深度确定性策略梯度(DDPG)
Chapter One Introduction
深度学习,“粮草”先行--浅谈数据集获取之道
MySQL存储过程学习笔记(基于8.0)
arm学习-1-开发板
How to get started with MOOSE platform - an example of how to run the official tutorial
MOOSE平台使用入门攻略——如何运行官方教程的例子
[开发杂项][VS Code]remote-ssd retry failed
位段-C语言
C语言静态变量static的分析
Machine Learning - Processing of Text Labels for Classification Problems (Feature Engineering)
file permission management ugo
The Unity of ML - agents interpret parameter Settings
[Daily Office][Miscellaneous][vscode]tab space
第一章 绪论
第二章 STA相关概念