-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhalloween_challenge.html
102 lines (77 loc) · 2.47 KB
/
halloween_challenge.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Halloween Challenge</title>
</head>
<body>
<script>
// FUNCTION ONE
function one (date) {
var presentmonth = 10;
var presentday = 24;
var month = date.substring(0, 2);
var monthInt = parseInt(month);
var day = date.substring(3,5);
var dayInt = parseInt(day);
var year = date.substring(6);
var yearInt = parseInt(year);
var age = (2017 - yearInt);
if (presentmonth - month <= 0) {
age = age - 1;
if (presentday - day <= 0) {
return age;
} else {
return 0;
}
}
return age;
}
console.log(one("02/16/1994"));
console.log(one("10/30/1965"));
// console.log(one("11/04/1982"));
// console.log(one("12/25/2016"));
// console.log(one("03/02/2010"));
// FUNCTION TWO
function two (string) {
var output = string.split(" ");
console.log(output);
}
string = "The greatest food ever";
two(string);
// FUNCTION THREE
function three (str, substr) {
let counter = 0;
let array = str.split(" ");
for (let i = 0; i < array.length; i++) {
array[i] = array[i].toLowerCase();
if (array[i] === substr) {
counter++;
}
}
return counter;
}
string = "coded coders coding code?";
substr = "code";
console.log(three(string, substr));
// FUNCTION FOUR
function four (string) {
var stringArray = string.split("");
console.log(stringArray);
var finalArray = [];
for (var i = 0; i < stringArray.length; i++) {
if (stringArray[i] !== "~" || "!" || "$" || "&" || "%" || "#" || "@" || "-" || "_" || "^" || "?" || " ") {
finalArray.push(stringArray[i])
} else {
}
}
console.log(finalArray);
}
var string = "Happy ~!&%#@- Halloween";
var string1 = "I'll bet living in a nudist-colony takes all the fun out of Halloween!!";
four(string);
// FUNCTION FIVE
function five () {}
</script>
</body>
</html>