-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquiz.js
More file actions
55 lines (47 loc) · 1.95 KB
/
quiz.js
File metadata and controls
55 lines (47 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
document.addEventListener("DOMContentLoaded", function () {
const form = document.getElementById("quizForm");
const resultBox = document.getElementById("quizResult");
form.addEventListener("submit", function (e) {
e.preventDefault();
const light = document.getElementById("light").value;
const water = document.getElementById("water").value;
const pets = document.getElementById("pets").value;
const experience = document.getElementById("experience").value;
const recommendation = getRecommendation(light, water, pets, experience);
resultBox.innerHTML = `
<h3>Your Recommended Plant:</h3>
<p><strong>${recommendation.name}</strong></p>
<img src="${recommendation.image}" alt="${recommendation.name}" style="width: 100%; max-width: 250px; border-radius: 12px;">
<p>${recommendation.description}</p>
`;
});
function getRecommendation(light, water, pets, experience) {
// Simplified logic
if (pets === "yes") {
return {
name: "Spider Plant",
image: "images/spider-plant.jpg",
description: "Pet-friendly and beginner-friendly. Tolerates low to medium light and infrequent watering."
};
}
if (light === "low" && water === "rarely") {
return {
name: "Snake Plant",
image: "images/snake-plant.jpg",
description: "Perfect for low-light homes. Needs watering only once a month."
};
}
if (light === "high" && water === "often" && experience !== "beginner") {
return {
name: "Fiddle Leaf Fig",
image: "images/fiddle-leaf.jpg",
description: "Loves sun and humidity. Great for experienced plant parents."
};
}
return {
name: "Pothos",
image: "images/pothos.jpg",
description: "Flexible with light and water, grows fast, and great for all skill levels."
};
}
});