第二章作业

1.利用wx:if及wx:for数据绑定来实现输出乘法口诀表的编程:

以下是部分代码展示:

.wxml

<view style="text-align: center;font-size: 9px;" wx:for="{{[1,2,3,4,5,6,7,8,9]}}" wx:for-item="i">
  <view style="display: inline-block;" wx:for="{{[1,2,3,4,5,6,7,8,9]}}" wx:for-item="j">
    <view wx:if="{{i<=j}}">
      {{i}}×{{j}}={{i*j}},
    </view>
  </view>
</view>

2.编写程序,在Console控制台输出水仙花数(水仙花数是指一个3位数的各位上的数字的3次幂之和等于他本身)
3.编写程序,在页面中输出水仙花数

以下是部分代码展示:

.JS

Page({ 
  data:{
  xshs: []
},
  onLoad: function () {
  this.findNarcissisticNumbers();
},
  findNarcissisticNumbers: function (){ 
    const numbers =[];
  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){ 
    numbers.push(i);
    console.log('水仙花数'+i)}}
  this.setData({
  xshs: numbers});}
});

4.编写程序,在页面中输出菱形图案

 以下是部分代码展示:

.JS

Page({
  data:{
    a1:'*',
    a2:'***',
    a3:'*****',
    a4:'*******',
    a4:'*********',
    a5:'*******',
    a7:'*****',
    a8:'***',
    a9:'*'
  }
})

.wxml

<view style="text-align: center;">{{a1}}</view>
<view style="text-align: center;">{{a2}}</view>
<view style="text-align: center;">{{a3}}</view>
<view style="text-align: center;">{{a4}}</view>
<view style="text-align: center;">{{a5}}</view>
<view style="text-align: center;">{{a6}}</view>
<view style="text-align: center;">{{a7}}</view>
<view style="text-align: center;">{{a8}}</view>
<view style="text-align: center;">{{a9}}</view>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值