创建一个新项目来装我们的第二次作业:No2
乘法口诀表
新建文件夹nxn,再去app.json里添加一下
然后创建旗下的文件:
nxn.js
Page({
data: {
table: []
},
onLoad: function () {
let table = []; for (let i = 1; i <= 9; i++) {
let row = [];
for (let j = 1; j <= 9; j++) {
row.push(i * j);
}
table.push(row);
}
this.setData({
table: table
});
}
})
nxn.json
{
"pages":[
]
}
nxn.wxml
<view class='row' wx:for="{{[1,2,3,4,5,6,7,8,9]}}" wx:for-item="row">
<view class='col' wx:for="{{[1,2,3,4,5,6,7,8,9]}}" wx:for-item="col" wx:if="{{col <= row}}">
{{col}}*{{row}} = {{col*row}}
</view>
</view>
nxn.wxss
.row{
font-size: 8px;
}
.col{
display: inline-block;
}
结果如图:
水仙花数
创建文件夹sxh,记入app.json
文件:
sxh.js
Page({
data: {
messagez:[]
},
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);
},
})
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});}
});
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});}
});
sxh.json
{
"navigationBarBackgroundColor": "#808080",
"navigationBarTitleText": "水仙花数",
"navigationBarTextStyle":"black",
"usingComponents": {}
}
sxh.wxml
<text>水仙花数:</text>
<view class="Shui">
<view class="shui">
<text wx:for="{{message}}" wx:key="*this">{{item}}
</text>
</view>
</view>
截图:
输出水仙花数
创建shuixianhuashu,记入app.json
文件:
shuixianhuashu.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});}
});
shuixianhuashu.json
{
"navigationBarBackgroundColor": "#808080",
"navigationBarTitleText": "水仙花数",
"navigationBarTextStyle":"black",
"usingComponents": {}
}
shuixianhuashu.wxml
<view class="sxhs">
<view class="narcissistic-numbers">
<text wx:for="{{narcissisticNumbers}}" wx:key="*this">{{item}}</text></view>
</view>
shuixianhuashu.wxss
.sxhs {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
}
.narcissistic-numbers {
margin-top: 20px;
}
.narcissistic-numbers text {
display: block;
margin-bottom: 10px;
}
截图:
菱形
创建文件夹ling,记入app.json
文件:
ling.js
// pages/ling/ling.js
Page({
/**
* 页面的初始数据
*/
data: {
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})
ling.json
{
"navigationBarBackgroundColor": "#808080",
"navigationBarTitleText": "菱形图案",
"navigationBarTextStyle":"black",
"usingComponents": {}
}
ling.wxml
<view class="diamond">
<view> *</view>
<view> ***</view>
<view> *****</view>
<view> *******</view>
<view>*********</view>
<view> *******</view>
<view> *****</view>
<view> ***</view>
<view> *</view>
</view>
ling.wxss
.diamond {
text-align: center;
margin-top: 20px;
font-size: 20px;
}
截图: