I want to make simple quiz. When user click on button new question display to him. I don't have idea how to do it.
index.js
const express = require('express')
const app = express()
app.set('view engine', 'pug')
app.use(express.urlencoded({ extended: false }))
app.get('/', (req, res) => {
questions = ['firstQuestion', 'secondQuestion']
for (i = 0;i<questions.length;i++) {
res.render('index', {question: question[i]})
}
})
app.listen(3000)
index.pug
html(lang="en")
head
meta(charset="UTF-8")
meta(http-equiv="X-UA-Compatible", content="IE=edge")
meta(name="viewport", content="width=device-width, initial-scale=1.0")
title Document
body
h1#a
button(onclick='func()')
script.
function func() {
document.getElementById("a").innerHTML = #{question}
}
I am not sure how pug works but I have some general ideas for you
Keep in mind that you will have to save the data somewhere (userId to userQuestionIndex).. its depends of how secured you want the app to be.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.