File tree 1 file changed +34
-0
lines changed
1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change 1
1
// TODO: write the validation functions
2
+ function isValidName ( name ) {
3
+ return typeof name === "string" && name !== "" && nonWhiteSpaceOfAtLeast3Chars ( name )
2
4
5
+ function nonWhiteSpaceOfAtLeast3Chars ( name ) {
6
+ return name . length >= 3 && name [ 0 ] !== " " && name [ 1 ] !== " " && name [ 2 ] !== " "
7
+ }
8
+ }
9
+
10
+ function hoursAttended ( attend , length ) {
11
+ return isStringOrNumber ( attend ) &&
12
+ isStringOrNumber ( length ) &&
13
+ canBeANumber ( attend ) &&
14
+ canBeANumber ( length ) &&
15
+ isZeroOrHigher ( attend ) &&
16
+ isZeroOrHigher ( length ) &&
17
+ isWholeNumber ( attend ) &&
18
+ isWholeNumber ( length ) &&
19
+ ( Number ( attend ) <= Number ( length ) )
20
+
21
+ function isStringOrNumber ( num ) {
22
+ return typeof num == "string" || typeof num == "number"
23
+ }
24
+
25
+ function canBeANumber ( num ) {
26
+ return Number ( num ) !== NaN && num !== ""
27
+ }
28
+
29
+ function isZeroOrHigher ( num ) {
30
+ return Number ( num ) >= 0
31
+ }
32
+
33
+ function isWholeNumber ( num ) {
34
+ return Number ( num ) % 1 == 0
35
+ }
36
+ }
3
37
4
38
5
39
// tests:
You can’t perform that action at this time.
0 commit comments