-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmind-reading-bgg.js
115 lines (114 loc) · 3.73 KB
/
mind-reading-bgg.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// Filename: public/mind-reading-bgg.js
// Code written in public files is shared by your site's
// Backend, page code, and site code environments.
// The following code demonstrates how to call the add
// function from your site's page code or site code.
/*
import {add} from 'public/mind-reading-bgg.js'
$w.onReady(function () {
let sum = add(6,7);
console.log(sum);
});
*/
// This function takes selected input fields are arguments and returns a string having users birthday or INVALID DATE for wrong user INPUT
export function findBirthday(birthdayInput, birthmonthInput) {
let birthdayCardNumbers = birthdayInput.value.trim();
let birthmonthCardNumbers = birthmonthInput.value.trim();
if (birthdayCardNumbers == "" || birthmonthCardNumbers == "") {
return 'Please enter both values';
}
let dayPowers = birthdayCardNumbers.split(" ");
let birthday = 0;
for (let i = 0; i < dayPowers.length; i++) {
birthday += Math.pow(2, parseInt(dayPowers[i].trim()));
}
let monthPowers = birthmonthCardNumbers.split(" ");
let birthMonth = 0;
for (let i = 0; i < monthPowers.length; i++) {
birthMonth += Math.pow(2, parseInt(monthPowers[i].trim()));
}
switch (birthMonth) {
case 1:
if (birthday > 0 && birthday < 32) {
return`Your birthday is on ${birthday} January`;
} else {
return "Invalid date";
}
case 2:
if (birthday > 0 && birthday < 29) {
return `Your birthday is on ${birthday} February`;
} else if (birthday == 29) {
return `Your birthday is on ${birthday} February (Leap Year)`;
} else {
return "Invalid date";
}
case 3:
if (birthday > 0 && birthday < 32) {
return `Your birthday is on ${birthday} March`;
} else {
return "Invalid date";
}
case 4:
if (birthday > 0 && birthday < 31) {
return `Your birthday is on ${birthday} April`;
} else {
return "Invalid date";
}
case 5:
if (birthday > 0 && birthday < 32) {
return `Your birthday is on ${birthday} May`;
} else {
return "Invalid date";
}
case 6:
if (birthday > 0 && birthday < 31) {
return `Your birthday is on ${birthday} June`;
} else {
return "Invalid date";
}
case 7:
if (birthday > 0 && birthday < 32) {
return `Your birthday is on ${birthday} July`;
} else {
return "Invalid date";
}
case 8:
if (birthday > 0 && birthday < 32) {
return `Your birthday is on ${birthday} August`;
} else {
return "Invalid date";
}
case 9:
if (birthday > 0 && birthday < 31) {
return `Your birthday is on ${birthday} September`;
} else {
return "Invalid date";
}
case 10:
if (birthday > 0 && birthday < 32) {
return `Your birthday is on ${birthday} October`;
} else {
return "Invalid date";
}
case 11:
if (birthday > 0 && birthday < 31) {
return `Your birthday is on ${birthday} November`;
} else {
return "Invalid date";
}
case 12:
if (birthday > 0 && birthday < 32) {
return `Your birthday is on ${birthday} December`;
} else {
return "Invalid date";
}
default:
return "Invalid month"
}
}
// This function resets the values of the input fields and the answer
export function reset(birthdayInput, birthmonthInput, answer) {
birthdayInput.value = '';
birthmonthInput.value = '';
answer.text = 'Can I Guess Your Birthday?';
}