当前位置:网站首页>使用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>
边栏推荐
- 【五一专属】阿里云ECS大测评#五一专属|向所有热爱分享的“技术劳动者”致敬#
- 数据库的简述与常用操作指南
- 位段-C语言
- LeetCode_Dec_1st_Week
- The second official example analysis of the MOOSE platform - about creating a Kernel and solving the convection-diffusion equation
- Postgresql snapshot
- 亚马逊云科技 Build On 2022 - AIot 第二季物联网专场实验心得
- LeetCode_Nov_1st_Week
- [日常办公][ssh]cheatsheet
- Design and implementation of legal aid platform based on asp.net (with project link)
猜你喜欢
随机推荐
LeetCode_Nov_2nd_Week
Copy攻城狮信手”粘“来 AI 对对联
LeetCode_22_Apr_4th_Week
[CV-Learning] Linear Classifier (SVM Basics)
理想的生活
MNIST手写数字识别 —— 基于Mindspore快速构建感知机实现十分类
Detailed steps to install MySQL
FAREWARE ADDRESS
基于BiGRU和GAN的数据生成方法
Copy Siege Lion 5-minute online experience MindIR format model generation
Design and implementation of legal aid platform based on asp.net (with project link)
Stream API
(Navigation page) OpenStack-M version - manual construction of two nodes - with video from station B
arm-3-中断体系结构
An abstract class, internal classes and interfaces
关于DG(域泛化)领域的PCL方法的代码实例
Cut the hit pro subtitles export of essays
bind()系统调用的用处
CAS无锁队列的实现
Windows10重置MySQL用户密码