Repository navigation
Expand file tree
/
Copy pathsolutionFunction.js
More file actions
216 lines (174 loc) · 3.62 KB
/
Copy pathsolutionFunction.js
File metadata and controls
216 lines (174 loc) · 3.62 KB
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
// 1
function tellFortune(jobTitle, geoLocation, partner, numKids) {
var future = 'You will be a ' + jobTitle + ' in ' + geoLocation + ' and married to ' +
partner + ' ' + ' with ' + numKids + ' kids.';
console.log(future);
}
tellFortune('bball player', 'spain', 'Shaq', 3);
tellFortune('stunt double', 'Japan', 'Ryan Gosling', 3000);
tellFortune('Elvis impersonator', 'Russia', 'The Oatmeal', 0);
// 2
function calculateDogAge(age) {
var dogYears = 7 * age;
return "Your doggie is " + dogYears + " years old in dog years!";
}
calculateDogAge(1);
calculateDogAge(0.5);
calculateDogAge(12);
//3
function calculateSupply(age, numPerDay) {
var maxAge = 100;
var totalNeeded = (numPerDay * 365) * (maxAge - age);
var message = 'You will need ' + totalNeeded + ' cups of tea to last you until the ripe old age of ' + maxAge;
return message;
}
calculateSupply(28, 36);
calculateSupply(28, 2.5);
calculateSupply(28, 400);
//4
function greet(name) {
return "Hello " + name + "!";
}
//5
// Pass didnt use the parameter x => cat
// Pass static parameter 7 => x
// Pass static parameter and use it '7' => x
//6
// all of them
function double3(x) {
return 2 * x;
}
//7
function cube(x) {
return x * x * x;
}
//8
function multiply(x, y) {
return x * y;
}
//9
function canIGetADrivingLicense(age) {
if (age >= 20) {
return "yes you can";
}
return "please come back after" + (20 - age) + "years to get one";
}
//10
function sameLength(string1, string2) {
if (string1.length === string2.length) {
return true;
}
return false;
}
//11
function largerNubmer(num1, num2) {
if (num1 > num2) {
return num1;
}
return num2;
}
//12
function smallerNubmer(num1, num2, num3) {
var min = num1
if (num2 < min) {
min = num2;
}
if (num3 < min) {
min = num3;
}
return min
}
//13
function shorterString(string1, string2, string3, string4, string5) {
var shorter = string1
if (string2.length < shorter.length) {
shorter = string2;
}
if (string3.length < shorter.length) {
shorter = string3;
}
if (string4.length < shorter.length) {
shorter = string4;
}
if (string5.length < shorter.length) {
shorter = string5;
}
return shorter
}
//14
function longerString(string1, string2, string3, string4) {
var longer = string1
if (string2.length > longer.length) {
longer = string2;
}
if (string3.length > longer.length) {
longer = string3;
}
if (string4.length > longer.length) {
longer = string4;
}
return longerString
}
//15
function isEven(num) {
if (num % 2 === 0) {
return true;
}
return false;
}
//16
function isOdd(num) {
if (num % 2 !== 0) {
return true;
}
return false;
}
//17
function positive(number) {
if (number > 0) {
return number;
}
return number * -1;
}
//18
function fullName(firstName, lastName) {
return firstName + ' ' + lastName;
}
//19
function average(num1, num2, num3, num4, num5) {
return (num1 + num2 + num3 + num4 + num5) / 5;
}
//20
function randomNumber() {
return Math.random();
}
//21
function randomBetweenNumbers(num1, num2) {
return Math.floor(Math.random() * (num2 - num1)) + num1
}
//22
function socreInUniversity(score) {
if (score >= 90 && score < 100)
return 'A';
if (score >= 80 && score < 90)
return 'B';
if (score >= 70 && score < 80)
return 'C';
if (score >= 60 && score < 70)
return 'D';
if (score >= 50 && score < 60)
return 'E';
if (score < 50)
return 'F';
}
//23
var count = 0
function counter() {
return ++count;
}
//24
function resetCounter() {
var oldCounter = count
count = 0;
return oldCounter + " and the count reset now";
}