samedi 24 avril 2021

How to display new question when user click button and previous question delete in node.js and pug?

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}
        }



Aucun commentaire:

Enregistrer un commentaire