In this scenario, I have set up a route to retrieve all the items stored in the question array. However, the issue at hand is that I only want to display a single item on the ejs page instead of all the items. Additionally, I would like to include a next button that will toggle to show the next single item. View a screenshot of the problem here
const userSchema = new mongoose.Schema({
email: String,
password: String,
question: []
});
app.get('/game', (req, res) => {
if (req.isAuthenticated()) {
const userId = req.user; // iD is provided by passport.js
User.find({ _id: userId }, (err, foundUser) => {
foundUser.forEach((user) => {
res.render('game', { questions: user.question }); //passing questions as an array variable to the ejs template
});
});
} else {
res.render('login');
}
});
<%-include('partials/header')%>
<div class="jumbotron">
<h1 class="display-4">
<%= questions%>// Will render the single item
</h1>
<hr class="my-4">
<button class="btn btn-primary btn-lg" name="btn" value="">Previous</button>
<button class="btn btn-primary btn-lg" name="btn" value="">Next</button>
</p>
</div>
<%-include('partials/footer')%>