This repository has been archived by the owner on Aug 2, 2023. It is now read-only.
generated from alchemycodelab/web-01-mushroom-festival
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
77 lines (64 loc) · 2.11 KB
/
app.js
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// import functions and grab DOM elements
import { renderMushroom, renderFriend } from './render-utils.js';
const friendsEl = document.querySelector('.friends');
const friendInputEl = document.getElementById('friend-input');
const mushroomsEl = document.querySelector('.mushrooms');
const addMushroomButton = document.getElementById('add-mushroom-button');
const addFriendButton = document.getElementById('add-friend-button');
// initialize state
let mushroomCount = 3;
const friendData = [
{
name: 'Erich',
satisfaction: 2,
},
{
name: 'Sarah',
satisfaction: 3,
},
{
name: 'Missael',
satisfaction: 1,
},
{
name: 'Soraya',
satisfaction: 2,
},
];
addMushroomButton.addEventListener('click', () => {
if (Math.random() > 0.5) {
alert('found a mushroom!');
mushroomCount++;
displayMushrooms();
} else {
alert('no luck!');
}
});
addFriendButton.addEventListener('click', () => {
// get the name from the input
// create a new friend object
// push it into the friends state array, passed in as an argument
// clear out the input element
// clear out and display all the friends (use a function here)
});
function displayFriends() {
// clear out the friends in DOM
// for each friend in state . . .
for (let friend of friendData) {
// use renderFriend to make a friendEl
// this is a clickable list, so . . .
// add an event listener to each friend
// and if the friend's satisfaction level is below 3 and you have mushrooms left
// increment the friends satisfaction and decrement your mushrooms
// clear out and display the updated friends and mushrooms (hint: displayFriends, displayMushrooms)
// append the friendEl to the friends list in DOM
}
}
function displayMushrooms() {
// clear out the mushroom div
for (let i = 0; i < mushroomCount; i++) {
// for each mushroom in your mushroom state, render and append a mushroom
}
}
displayFriends();
displayMushrooms();