微信小程序第二章作业

1.乘法口诀表

1.js文件代码

Page({
  data: {
    logs: [],
    array:[9,8,7,6,5,4,3,2,1],
  },
  
})

2.json文件代码

{
  "navigationBarTitleText": "乘法口诀表",
  "usingComponents": {}
}

3.wxml代码

<view id="center">
  九九乘法口诀表
</view> 
  <view class="border" >
    <view wx:for="{{array}}" wx:for-item="i">
      <view class="inline" wx:for="{{array}}" wx:for-item="j">
        <view class="size" wx:if="{{i>=j}}">
          {{i}}*{{j}}={{i*j}}
        </view>
      </view>
    </view>
  </view>

4.wxss代码

.log-list {
  display: flex;
  flex-direction: column;
  padding: 40rpx;
}
.log-item {
  margin: 10rpx;
}
.inline{
  display:inline-block;
}
.size{
  font-size: 9px;
  padding-right:1em;
}
.border{
  border: 1px solid skyblue;
}
#center{
  font-weight: 700;
  text-align: center;
}
.ling{
  margin-left: 200px;
}
.b{
  margin-left: -6.5px;
}
.c{
  margin-left: -13px;
}
.d{
  margin-left: -20px;
}
.e{
  margin-left: -27px;
}

5.运行结果

2.输出水仙花数

1.js代码

Page({ 
  data:{
    txw: []
  },
  onLoad: function () {
    this.findNarcissisticNumbers();
  },
    findNarcissisticNumbers: function (){ 
       const numb =[];
        for (let i=100;i<1000;i++){
          const a = Math.floor(i / 100);
         const b = Math.floor((i % 100) / 10); const c=i% 10;
         if (a ** 3 + b** 3 +c**3===i){ 
           numb.push(i);
         }
        }
       this.setData({txw: numb});
       console.log(numb);
    }
  });

2.json代码

{
  "navigationBarTextStyle": "black",
  "navigationBarTitleText": "水仙花数",
  "navigationBarBackgroundColor": "#ffffff"
 }

3.wxml代码

<view class="txw">
  <view class="t">
    <text wx:for="{{txw}}" wx:key="*this">
      {{item}}
    </text>
  </view>
</view>

4.wxss代码

.txw { 
  display: flex;
  align-items: center;
  justify-content: center;
   height: 80vh;
}
.t text{
  display: block;
}

5.运行结果

3.输出菱形

1.js代码

Page({
  data: {
    diamondLines: []
  },
  onLoad: function () {
    const diamondLines = this.generateDiamond(5);
    this.setData({
      diamondLines: diamondLines
    });
  },
  generateDiamond: function (height) {
    const lines = [];
    for (let i = 1; i <= height; i++) {
      let line = '';
      for (let j = 1; j <= height - i; j++) {
        line += ' ';
      }
      for (let k = 1; k <= 2 * i - 1; k++) {
        line += '*';
      }
      lines.push(line);
    }
    for (let i = height - 1; i >= 1; i--) {
      let line = '';
      for (let j = 1; j <= height - i; j++) {
        line += ' ';
      }
      for (let k = 1; k <= 2 * i - 1; k++) {
        line += '*';
      }
      lines.push(line);
    }
    return lines;
  }
});

2.json代码

{
    "navigationBarTitleText": "菱形",
    "usingComponents": {}

}

3.wxml代码

<view class="container">
  <view class="diamond">
    <view wx:for="{{diamondLines}}" wx:key="{{index}}">
      <text>{{item}} </text>
    </view>
  </view>
</view>

4.wxss代码

.container {
  display: flex;
  vertical-align: middle;
  text-align: center;
}
.diamond {
  margin-top: 100px;
}
.container text {
  margin: 5px;
}

5.运行结果

  • 7
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值