59 lines
1.1 KiB
JavaScript
59 lines
1.1 KiB
JavaScript
|
|
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);
|