You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: challenges/functions.js
+77Lines changed: 77 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -3,6 +3,10 @@
3
3
4
4
// Step 1: Create a higher-order function that will accept 3 parameters. The first two can take any argument. The last is your callback. This function should return your callback that passed the first two parameters as its argument.
5
5
6
+
functionconsume(x,y,cb){
7
+
returncb(x,y);
8
+
}
9
+
6
10
/* Step 2: Create several functions that you will callback with the previous higher order function.
7
11
The first will return the sum of two numbers.
8
12
The second will return the product of two numbers.
@@ -18,5 +22,78 @@ The eleventh will return whether the firstNumber is less than or equal to the se
18
22
The twelvth will return whether the firstNumber is equivalent to the secondNumber.
19
23
The thirteenth will return a string 'Hey the number is firstNumber' if firstNumber is greater than the secondNumber. If it isn't, return a string 'Hey the number is secondNumber'
20
24
*/
25
+
functionadd(num1,num2){
26
+
returnnum1+num2;
27
+
}
28
+
29
+
// The second will return the product of two numbers.
30
+
functionmultiply(num1,num2){
31
+
returnnum1*num2;
32
+
}
33
+
// The third will return the modulus of the two numbers.
34
+
functionremainder(num1,num2){
35
+
returnnum1%num2;
36
+
}
37
+
// The fourth will return the quotient of the two numbers.
38
+
functiondivide(num1,num2){
39
+
returnnum1/num2;
40
+
}
41
+
// The fifth will return the square root of the two numbers.
42
+
functionsquare(num1,num2){
43
+
letvar1=Math.sqrt(num1);
44
+
letvar2=Math.sqrt(num2);
45
+
// return var1 + " " + var2;
46
+
return`${var1}${var2}`;
47
+
}
48
+
// The sixth will accept a first and last name and return 'Hey, firstName lastName, youre a wicked cool dev'.
49
+
functionstringReturn(firstName,lastName){
50
+
return`Hey, ${firstName}${lastName}, youre a wicked cool dev`;
51
+
}
52
+
// The seventh will return whether the firstString is included the secondString.
53
+
functionstringIncludes(firstString,secondString){
54
+
returnsecondString.includes(firstString);
55
+
}
56
+
// The eigth will return whether the firstNumber is greater than the secondNumber.
57
+
functionnumCompare1(x,y){
58
+
returnx>y;
59
+
}
60
+
// The ninth will return whether the firstNumber is less than the secondNumber.
61
+
functionnumCompare2(x,y){
62
+
returnx<y;
63
+
}
64
+
// The tenth will return whether the firstNumber is greater than or equal to the secondNumber.
65
+
functionnumCompare3(x,y){
66
+
returnx>=y;
67
+
}
68
+
// The eleventh will return whether the firstNumber is less than or equal to the secondNumber.
69
+
functionnumCompare4(x,y){
70
+
returnx<=y;
71
+
}
72
+
// The twelvth will return whether the firstNumber is equivalent to the secondNumber.
73
+
functionnumCompare5(x,y){
74
+
returnx===y;
75
+
}
76
+
// The thirteenth will return a string 'Hey the number is firstNumber' if firstNumber is greater than the secondNumber. If it isn't, return a string 'Hey the number is secondNumber'
77
+
functionnumCompare6(x,y){
78
+
if(x>y){
79
+
return`Hey the number is ${x}`;
80
+
}else{
81
+
return`Hey the number is ${y}`;
82
+
}
83
+
}
84
+
21
85
22
86
// Step 3: Check your work using console.log and invoke your higher order function.
// Create a new bark method for the dog. When called, return "Woof!"
21
61
// Create a new hunt method for the tiger. When called, if Math.random(10) is greater than 7, return "Tiger hunt successful" and add 5lb to the weight. If it is not, return "Tiger goes hungry" and subtract 5lbs to the weight.
22
62
// Create a new climb method for the koala. When called, return "Eucalyptus is great"
23
-
24
-
63
+
console.log(dog.bark());
64
+
console.log(tiger.hunt(),tiger.weight);
65
+
console.log(koala.climb(),koala.weight);
25
66
// Arrays
26
67
27
68
// Given this array of game characters, complete the following tasks
@@ -39,8 +80,29 @@ const gameCharacters = [
39
80
// Step 1: Create a new array that will contain all games. Once you have it made, sort it ascending[A-Z]. Log the result. Solve two ways:
Copy file name to clipboardExpand all lines: challenges/prototypes.js
+22-3Lines changed: 22 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -3,11 +3,30 @@
3
3
// Task: You are to build a pentagonal pyramid that can return values for its volume as well as its surface areas. Follow the steps to achieve this.
4
4
5
5
// Step 1: Base Constructor -- You should create a constructor function names PentagonalPyramid that will accept properties for its base edge, and heights.
6
+
functionPentagonalPyramid(attr){
7
+
this.edge=attr.edge;
8
+
this.height=attr.height;
9
+
}
6
10
7
-
// Step 2: Volume Method -- You should create a prototype for PentagonalPyramid that returns the volume of a pentagonal pyramid. Curious about the formula??? Use Google (A DEVELOPERS BEST FRIEND)
11
+
// Step 2: Volume Method -- You should create a prototype for PentagonalPyramid that returns the volume of a pentagonal pyramid. Curious about the formula??? Use Google (A DEVELOPERS BEST FRIEND
// Step 3: Surface Area Method -- You should create a prototype fro PentagonalPyramid that returns the surface area of a pentagonal pyramid. Curious about the formula??? Use Google (A DEVELOPERS BEST FRIEND)
0 commit comments