-
Notifications
You must be signed in to change notification settings - Fork 0
/
wimbo.js
68 lines (48 loc) · 2.02 KB
/
wimbo.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
// console.log('loaded')
//create a array of names
let namesOfRegisteredPersons = ['Ann','Lilian','Joy','Nzau'];
// console.log(myList);
//create a new empty array to hold the names to be entered by user
let personsWhoHaveEaten = [];
// console.log(nameKnown);
//define submit function
function submit(){
// console.log(submit);
//getting the name entered by user in html
let nameEnteredByUser = document.getElementById('result').value;
// console.log(newList);
//checking if name given by user is included in the array myListi
let ifNameIsIncluded = namesOfRegisteredPersons.includes(nameEnteredByUser);
// console.log(nameList);
//if name is included in myList array
if (ifNameIsIncluded){
// console.log('You are registered');
//getting name using id regist to give output
$('#regist').html("You are registered")
//checking if name entered by user is included in the array of people who have eaten
let personEaten = personsWhoHaveEaten.includes(nameEnteredByUser)
// console.log(personEaten);
//checking if the person has eaten
if (personEaten){
// console.log("You have eaten");
//getting name using id ifeaten to give output
$("#ifeaten").html("You have eaten")
}else{
// console.log("You haven't eaten");
//getting name using id ifeaten to give output
$("#ifeaten").html("You haven't eaten")
//pushing name to persons who have eaten if person is taking meal for the first time
personsWhoHaveEaten.push(nameEnteredByUser)
}
}else{
// console.log('you are not registered');
//getting name using id regist to give output
$("#regist").html("You are not registered")
}
}
//define reset function
function reset(){
// console.log(reset)
//getting value from html by id result and reset the string to empty string
document.getElementById('result').value = '';
}