;]; 2. Random number implementation, the code is [goto_logs: function(){}]."/> ;]; 2. Random number implementation, the code is [goto_logs: function(){}].">

Home  >  Article  >  WeChat Applet  >  How does the quiz mini program randomly post questions?

How does the quiz mini program randomly post questions?

PHPz
PHPzOriginal
2020-09-25 16:10:403595browse

How to randomly post questions in the answer applet: 1. To implement the question, the code is [;]; 2. Random number implementation, the code is [goto_logs: function(){}].

How does the quiz mini program randomly post questions?

##Related learning recommendations: WeChat Mini Program Development

How to randomly post questions in the answer applet:

The initial interface is as shown in 1. If you enter the wrong answer, click OK and make sure the text below shows "Wrong!" , click to jump, and an integer between 0 and 9 is randomly generated below the jump, as shown in 2. The answer is entered correctly, click OK, and the text display is "Right!".

Start with simplicity and forget about anything else.

index.wxml code:

<form bindsubmit="formBindsubmit">
  <view style="display:flex;">
    <label>请问你的名字?</label>
  </view>
  <view style="display:flex;">
    <label>答案:</label>
    <input name="psw" placeholder="请输入答案!"/>
  </view>
  <view style="display:flex;margin-top:30px;">
    <button style="width:30%;" formType="submit" >确定</button>
  </view>
</form>
<view>{{tip}}</view>
<view style="display:flex;margin-top:30px;">
  <button style="width:30%;" bindtap="goto_logs" >跳转</button>
</view>
<view>{{suiji}}</view>

The first group is the implementation of the problem. The form component contains view, input, and button, and the returned value is tip.

The second group is the implementation of random numbers, button, and the returned value is suiji.

index.js code:

Page({
  data: {
    // text:"这是一个页面"
    tip: &#39;对错&#39;,
    suiji:&#39;00&#39;
  },
  formBindsubmit: function (e) {
    if (e.detail.value.psw == "无面人") {
      this.setData({
        tip: &#39;对了!&#39;
    })
    }
    else {
      this.setData({
        tip: &#39;错了!&#39;
      })
    }
  },
  goto_logs: function () {
    var random = Math.floor(Math.random() * 10);
    this.setData({
      suiji: random
    })
    
  },
 
 })

The formBindsubmit function is the problem. The correct answer is "faceless man". If you enter "faceless man", it will prompt "right!" otherwise "wrong" !".

The goto_logs function is random, mainly in this line var random = Math.floor(Math.random() * 10); takes a value between [0,10), including 0, but not including 10 .

Achievement effect:

How does the quiz mini program randomly post questions?

The above is the detailed content of How does the quiz mini program randomly post questions?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn