Files
FH/WS24_25/WebTech/web-pruefung-projekt2/aufgabe6/models/bilder.js
2025-02-13 18:50:22 +01:00

56 lines
1.2 KiB
JavaScript

const bilder = [
{
dateiname: "robot.png",
beschreibung: "Frida Kahlo painting of a robot waving goodbye",
},
{
dateiname: "meadow.png",
beschreibung:
"A photo of a wide green meadow and a clear blue sky",
},
{
dateiname: "elephant.png",
beschreibung: "A pink elephant in a small room",
},
{
dateiname: "fhdortmund.png",
beschreibung: "An expressive oil painting of FH Dortmund in summer",
},
];
// Hier den Code ergaenzen!
module.exports = {
holeStartBild: function () {
return {
bild: bilder[0],
index: 0,
};
},
vor: function (aktuellerIndex) {
const neuerIndex = (aktuellerIndex + 1) % bilder.length;
return {
bild: bilder[neuerIndex],
index: neuerIndex,
};
},
zurueck: function (aktuellerIndex) {
let neuerIndex = aktuellerIndex - 1;
if (neuerIndex < 0) {
neuerIndex = bilder.length - 1;
}
return {
bild: bilder[neuerIndex],
index: neuerIndex,
};
},
holeBildMitIndex: function (index) {
const validIndex = Math.max(0, Math.min(index, bilder.length - 1));
return {
bild: bilder[validIndex],
index: validIndex,
};
},
};