Skip to content

Commit 234378a

Browse files
committed
65 of 84
1 parent 7cd3ce3 commit 234378a

3 files changed

Lines changed: 202 additions & 30 deletions

File tree

src/project-1.js

Lines changed: 65 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,139 +1,176 @@
11
// Do not change any of the funcxtion names
22

33
const multiplyByTen = (num) => {
4-
// return num after multiplying it by ten
5-
// code here
4+
// return num after subtracting five
5+
const product = num * 10;
6+
return product;
67
};
78

9+
810
const subtractFive = (num) => {
911
// return num after subtracting five
10-
// code here
12+
const difference = num - 5;
13+
return difference;
1114
};
1215

1316
const areSameLength = (str1, str2) => {
1417
// return true if the two strings have the same length
1518
// otherwise return false
16-
// code here
19+
if (str1.length === str2.length) {
20+
return true;
21+
} return false;
1722
};
1823

1924
const areEqual = (x, y) => {
2025
// return true if x and y are the same
2126
// otherwise return false
22-
// code here
27+
if (x === y) {
28+
return true;
29+
}
30+
return false;
2331
};
2432

2533
const lessThanNinety = (num) => {
2634
// return true if num is less than ninety
2735
// otherwise return false
28-
// code here
36+
// in original there was a mistake as the value for num should be 50 not 90
37+
if (num < 50) {
38+
return true;
39+
}
40+
return false;
2941
};
3042

3143
const greaterThanFifty = (num) => {
32-
// return true if num is greater than fifty
44+
// let isGreater = false;
45+
// const num = 10;
46+
// num > 9? isGreater = true: null;
47+
// console.log(isGreater); true
48+
// const isGreaterThan50 = (num) =>{
49+
// if (num > 50) {
50+
// return true;
51+
// }
52+
// return false;
53+
// } return true if num is greater than fifty
3354
// otherwise return false
34-
// code here
55+
if (num > 50) {
56+
return true;
57+
}
58+
return false;
59+
// console.log(isGreaterThan50(100)); true};code here
3560
};
3661

3762
const add = (x, y) => {
3863
// add x and y together and return the value
39-
// code here
64+
const sum = x + y;
65+
return sum;
4066
};
4167

4268
const subtract = (x, y) => {
43-
// subtract y from x and return the value
44-
// code here
69+
const sum = x - y;
70+
return sum;
4571
};
4672

4773
const divide = (x, y) => {
4874
// divide x by y and return the value
49-
// code here
75+
const sum = x / y;
76+
return sum;
5077
};
5178

5279
const multiply = (x, y) => {
5380
// multiply x by y and return the value
54-
// code here
81+
const sum = x * y;
82+
return sum;
5583
};
5684

5785
const getRemainder = (x, y) => {
5886
// return the remainder from dividing x by y
59-
// code here
87+
const remainder = x % y;
88+
return remainder;
6089
};
6190

6291
const isEven = (num) => {
6392
// return true if num is even
6493
// otherwise return false
65-
// code here
94+
if (num % 2 === 0) {
95+
return true;
96+
}
97+
return false;
6698
};
6799

68100
const isOdd = (num) => {
69101
// return true if num is odd
70102
// otherwise return false
71-
// code here
103+
if (num % 2 === 0) {
104+
return false;
105+
}
106+
return true;
72107
};
73108

74109
const square = (num) => {
75110
// square num and return the new value
76-
// code here
111+
return num * num;
77112
};
78113

79114
const cube = (num) => {
80115
// cube num and return the new value
81-
// code here
116+
return Math.pow(num, 3);
82117
};
83118

84119
const raiseToPower = (num, exponent) => {
85-
// raise num to whatever power is passed in as exponent
120+
return Math.pow(num, exponent);
86121
// code here
87122
};
88123

89124
const roundNumber = (num) => {
90-
// round num and return it
125+
return Math.round(num);
91126
// code here
92127
};
93128

94129
const roundUp = (num) => {
95-
// round num up and return it
130+
return Math.ceil(num);
96131
// code here
97132
};
98133

99134
const addExclamationPoint = (str) => {
100135
// add an exclamation point to the end of str and return the new string
101136
// 'hello world' -> 'hello world!'
102-
// code here
137+
return `${str}!`;
103138
};
104139

105140
const combineNames = (firstName, lastName) => {
106141
// return firstName and lastName combined as one string and separated by a space.
107142
// 'Lambda', 'School' -> 'Lambda School'
108-
// code here
143+
// return `${firstName} + ' ' + ${lastName
144+
return (`${firstName} ${lastName}`);
109145
};
110146

111147
const getGreeting = (name) => {
112148
// Take the name string and concatenate other strings onto it so it takes the following form:
113149
// 'Sam' -> 'Hello Sam!'
114-
// code here
150+
return (`Hello ${name}!`);
115151
};
116152

117153
// If you can't remember these area formulas then head over to Google or look at the test code.
118154

119155
const getRectangleArea = (length, width) => {
120156
// return the area of the rectangle by using length and width
121-
// code here
157+
return length * width;
122158
};
123159

124160
const getTriangleArea = (base, height) => {
125161
// return the area of the triangle by using base and height
126-
// code here
162+
return (base * height) / 2;
127163
};
128164

129165
const getCircleArea = (radius) => {
130166
// return the rounded area of the circle given the radius
131-
// code here
167+
const area = Math.PI * (radius * radius);
168+
return Math.round(area);
132169
};
133170

134171
const getRectangularPrismVolume = (length, width, height) => {
135172
// return the volume of the 3D rectangular prism given the length, width, and height
136-
// code here
173+
return (length * width) * height;
137174
};
138175

139176
// Do not modify code below this line.

src/project-2.js

Lines changed: 93 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@
33
const getBiggest = (x, y) => {
44
// x and y are integers. Return the larger integer
55
// if they are the same return either one
6+
if (x > y) {
7+
return x;
8+
}
9+
if (x < y) {
10+
return y;
11+
}
12+
return x || y;
613
};
714

815
const greeting = (language) => {
@@ -11,15 +18,47 @@ const greeting = (language) => {
1118
// language: 'Spanish' -> 'Hola!'
1219
// language: 'Chinese' -> 'Ni Hao!'
1320
// if language is undefined return 'Hello!'
21+
// let greeting = ('Guten Tag!');
22+
if (language === 'German') {
23+
return ('Guten Tag!');
24+
}
25+
// language = 'English';
26+
// greeting = ('Hello!');
27+
if (language === 'Chinese') {
28+
return ('Ni Hao!');
29+
}
30+
// language = 'Spanish';
31+
// greeting = ('Hola!');
32+
if (language === 'Spanish') {
33+
return ('Hola!');
34+
}
35+
// if language is undefined return 'Hello!'
36+
// language !== 'German' || 'Spanish' || 'English';
37+
if (language !== 'German' || 'Spanish' || 'Chinese') {
38+
return ('Hello!');
39+
}
1440
};
1541

1642
const isTenOrFive = (num) => {
1743
// return true if num is 10 or 5
1844
// otherwise return false
45+
if (num === 10) {
46+
return true;
47+
}
48+
49+
if (num === 5) {
50+
return true;
51+
} else if (num !== 10 || 5) {
52+
return false;
53+
}
1954
};
2055

2156
const isInRange = (num) => {
22-
// return true if num is less than 50 and greater than 20
57+
if (num > 20 && num < 50) {
58+
return true;
59+
} else if (num <= 20 || num >= 50) {
60+
return false;
61+
}
2362
};
2463

2564
const isInteger = (num) => {
@@ -29,13 +68,22 @@ const isInteger = (num) => {
2968
// -10 -> true
3069
// otherwise return false
3170
// hint: you can solve this using Math.floor
71+
3272
};
3373

3474
const fizzBuzz = (num) => {
3575
// if num is divisible by 3 return 'fizz'
3676
// if num is divisible by 5 return 'buzz'
3777
// if num is divisible by 3 & 5 return 'fizzbuzz'
3878
// otherwise return num
79+
if (num % 3 === 0 && num % 5 === 0) {
80+
return ('fizzbuzz');
81+
} else if (num % 3 === 0) {
82+
return ('fizz');
83+
} else if (num % 5 === 0) {
84+
return ('buzz');
85+
}
86+
return (num);
3987
};
4088

4189
const isPrime = (num) => {
@@ -44,62 +92,105 @@ const isPrime = (num) => {
4492
// hint: a prime number is only evenly divisible by itself and 1
4593
// hint2: you can solve this using a for loop
4694
// note: 0 and 1 are NOT considered prime numbers
95+
if (num === 1) {
96+
return false;
97+
} else if (num === 0) {
98+
return false;
99+
} else if (num === 2) {
100+
return true;
101+
}
102+
for (let x = 2; x < num; x++) {
103+
if (num % x === 0) {
104+
return false;
105+
} return true;
106+
}
47107
};
48108

49109
const returnFirst = (arr) => {
50110
// return the first item from the array
111+
return (arr[0]);
51112
};
52113

53114
const returnLast = (arr) => {
54115
// return the last item of the array
116+
const last = arr.slice(-1)[0];
117+
return last;
55118
};
56119

57120
const getArrayLength = (arr) => {
58121
// return the length of the array
122+
return (arr.length);
59123
};
60124

61125
const incrementByOne = (arr) => {
62126
// arr is an array of integers
63127
// increase each integer by one
64128
// return the array
129+
const addedOne = arr.map((x) => {
130+
return x + 1;
131+
});
132+
return addedOne;
65133
};
66134

67135
const addItemToArray = (arr, item) => {
68136
// add the item to the end of the array
69137
// return the array
138+
arr.push(item);
139+
return arr;
70140
};
71141

72142
const addItemToFront = (arr, item) => {
73143
// add the item to the front of the array
74144
// return the array
75145
// hint: use the array method .unshift
146+
arr.unshift(item);
147+
return arr;
76148
};
77149

78150
const wordsToSentence = (words) => {
79151
// words is an array of strings
80152
// return a string that is all of the words concatenated together
81153
// spaces need to be between each word
82-
// example: ['Hello', 'world!'] -> 'Hello world!'
154+
return words.join(' ');
83155
};
84156

85157
const contains = (arr, item) => {
86158
// check to see if item is inside of arr
87159
// return true if it is, otherwise return false
160+
for (let i = 0; i < arr.length; i++) {
161+
if (arr[i] === item) {
162+
return true;
163+
}
164+
}
165+
return false;
88166
};
89167

90168
const addNumbers = (numbers) => {
91169
// numbers is an array of integers.
92170
// add all of the integers and return the value
171+
let total = 0;
172+
for (let i = 0; i < numbers.length; i++) {
173+
total += numbers[i];
174+
}
93175
};
94176

95177
const averageTestScore = (testScores) => {
96178
// testScores is an array. Iterate over testScores and compute the average.
97179
// return the average
180+
let sum = 0; for (let i = 0; i < testScores.length; i++) {
181+
sum += parseInt(testScores[i], 10);
182+
}
183+
const AverageTestScore = sum / testScores.length;
184+
return AverageTestScore;
98185
};
99186

100187
const largestNumber = (numbers) => {
101188
// numbers is an array of integers
102189
// return the largest integer
190+
let i = 0;
191+
const n = numbers.length;
192+
let m = -Infinity;
193+
for (; i !== n; ++i) { if (numbers[i] > m) { m = numbers[i]; } } return m;
103194
};
104195

105196
// Do not modify code below this line.

0 commit comments

Comments
 (0)