Grundgerüst
This commit is contained in:
58
script.js
Normal file
58
script.js
Normal file
@@ -0,0 +1,58 @@
|
||||
|
||||
let currentMonth = 1;
|
||||
|
||||
|
||||
function getFibonacci(n) {
|
||||
if (n <= 2) return 1;
|
||||
|
||||
let a = 1, b = 1;
|
||||
|
||||
for (let i = 3; i <= n; i++) {
|
||||
let next = a + b;
|
||||
a = b;
|
||||
b = next;
|
||||
}
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
|
||||
function showMonth(month) {
|
||||
document.getElementById("monthDisplay").textContent = "Monat: " + month;
|
||||
}
|
||||
|
||||
|
||||
function clearRabbits() {
|
||||
document.getElementById("rabbitContainer").innerHTML = "";
|
||||
}
|
||||
|
||||
|
||||
function createRabbitPair() {
|
||||
const pair = document.createElement("div");
|
||||
pair.classList.add("rabbit");
|
||||
pair.textContent = "🐇🐇";
|
||||
return pair;
|
||||
}
|
||||
|
||||
|
||||
function showRabbits(count) {
|
||||
clearRabbits();
|
||||
const container = document.getElementById("rabbitContainer");
|
||||
|
||||
for (let i = 0; i < count; i++) {
|
||||
container.appendChild(createRabbitPair());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function nextMonth() {
|
||||
currentMonth++;
|
||||
showMonth(currentMonth);
|
||||
|
||||
const rabbitCount = getFibonacci(currentMonth);
|
||||
showRabbits(rabbitCount);
|
||||
}
|
||||
|
||||
|
||||
document.getElementById("nextMonthButton")
|
||||
.addEventListener("click", nextMonth);
|
||||
Reference in New Issue
Block a user