;]; 2. Random number implementation, the code is [goto_logs: function(){}]."/> ;]; 2. Random number implementation, the code is [goto_logs: function(){}].">
search
HomeWeChat AppletMini Program DevelopmentHow does the quiz mini program randomly post questions?

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools