6 technically incorrect

This commit is contained in:
2025-02-05 12:20:00 +01:00
parent 9844efeaad
commit c0cf1f4177
10 changed files with 59 additions and 16 deletions

View File

@@ -1,9 +1,24 @@
const express = require("express");
const app = express();
const data = require("./models/bilder");
const url = require("url")
app.set("view engine", "ejs");
app.set("views", "views");
// Hier Code ergaenzen!
const router = express.Router();
app.use(express.static("public"));
router.get("/", function(req,res){
const param = url.parse(req.url, true).query;
var current = Number(param.num) || 0;
res.render("home",{
current: current,
next: data.vor(current),
prev: data.zurueck(current),
bild : data.holeStartBild(current),
});
});
app.use(router);
app.listen(8910);

View File

@@ -18,4 +18,27 @@ const bilder = [
},
];
function holeStartBild(num){
return bilder[num];
}
function vor(current){
var next = current + 1;
if(next >= bilder.length){
next = 0;
}
return next;
}
function zurueck(current){
var prev = current - 1;
if(prev < 0){
prev = bilder.length - 1;
}
return prev;
}
// Hier den Code ergaenzen!
module.exports.bilder = bilder;
module.exports.holeStartBild = holeStartBild;
module.exports.vor = vor;
module.exports.zurueck = zurueck;

View File

@@ -4,6 +4,7 @@
"description": "",
"main": "app.js",
"scripts": {
"run": "node app.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",

View File

@@ -18,9 +18,13 @@
<body>
<!-- Hier den Code ergaenzen -->
<figure>
<figcaption><%= bild.beschreibung %></figcaption>
<img src="<%= `img/${bild.dateiname}` %>">
</figure>
<a href="zurueck">Zurück</a> |
<a href="vor">Vor</a>
<a href="/?num=<%= prev %>">Zurück</a> |
<a href="/?num=<%= next %>">Vor</a>
</body>
</html>