第二章作业

第一题 九九乘法表

运行结果

运行代码

.wxml

<!--index.wxml-->
<view class='con'>
  <view wx:for="{{[1,2,3,4,5,6,7,8,9]}}" wx:for-item="i"><!--对应行-->
    <view class='inline' wx:for="{{[1,2,3,4,5,6,7,8,9]}}" wx:for-item="j"><!--对应列-->
      <view wx:if="{{j<=i}}">
        {{i}}×{{j}}={{i*j}}
      </view>
    </view>
  </view>
</view>

.wxss

/** index.wxss **/

.con {
  font-size: 16px; /** 设置字体大小 **/
  margin: 10px; /** 设置外边距 **/
}

.inline {
  display: inline-block; /** 设置布局,一行显示,**/
  width: 65px; /** 设置宽度 block的**/
}

.json

{
  "navigationBarBackgroundColor": "#000000",
  "navigationBarTitleText": "九九乘法表",
  "navigationBarTextStyle": "white",
  "backgroundTextStyle": "dark"
}

第二题 在Console控制台输出水仙花数

运行结果

运行代码

.js

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

.wxml

<view class="App">
<view class="app">
  <text wx:for="{{message}}" wx:key="*this">{{item}}</text>
</view>
</view>

第三题 在页面输出水仙花数

运行结果

运行代码

.js

Page({ 
  data:{
  narcissisticNumbers: []
},
  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);}}
  this.setData({
  narcissisticNumbers: numbers});}
  });

.json

{
  "navigationBarBackgroundColor": "#000000",
  "navigationBarTextStyle": "white",
  "backgroundTextStyle": "dark"
}

.wxml

<view class="one">
  <view class="two">水仙花数</view>
  <view class="three">
    <text class="three">水仙花数共有:153,370,371,407</text>
  </view>
</view>

.wxss

/* pages/news3/news3.wxss */
.two{
  padding-top: 70px;
  text-align: center;
  margin-bottom: 50px;
  font-weight: bold;
}
.three{
  text-align: center;
  padding-bottom: 270px;
  display: block;
}

第四题 在页面中显示菱形图案

运行结果

运行代码

.json

{
  "navigationBarTextStyle": "black",
  "navigationBarTitleText": "菱形",
  "navigationBarBackgroundColor": "#ffffff"
}

.wxml

<view class="diamond">
  <view>    *</view>
  <view>   ***</view>
  <view>  *****</view>
  <view> *******</view>
  <view>*********</view>
  <view> *******</view>
  <view>  *****</view>
  <view>   ***</view>
  <view>    *</view>
</view>

.wxss

.diamond {
  text-align: center;
  margin-top: 30px;
  font-size: 30px;
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值