Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 52c65d2

Browse filesBrowse files
Ryan HamblinRyan Hamblin
authored andcommitted
added solutions
1 parent b2098d3 commit 52c65d2
Copy full SHA for 52c65d2

File tree

Expand file treeCollapse file tree

4 files changed

+199
-180
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

4 files changed

+199
-180
lines changed
Open diff view settings
Collapse file

‎src/project-1.js‎

Copy file name to clipboardExpand all lines: src/project-1.js
+37-66Lines changed: 37 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,144 +1,115 @@
1-
// Do not change any of the funcxtion names
2-
31
const multiplyByTen = (num) => {
4-
// return num after multiplying it by ten
5-
// code here
2+
return num * 10;
63
};
74

85
const subtractFive = (num) => {
9-
// return num after subtracting five
10-
// code here
6+
return num - 5;
117
};
128

139
const areSameLength = (str1, str2) => {
14-
// return true if the two strings have the same length
15-
// otherwise return false
16-
// code here
10+
return str1.length === str2.length;
1711
};
1812

1913
const areEqual = (x, y) => {
20-
// return true if x and y are the same
21-
// otherwise return false
22-
// code here
14+
return x === y;
2315
};
2416

2517
const lessThanNinety = (num) => {
26-
// return true if num is less than ninety
27-
// otherwise return false
28-
// code here
18+
if (num < 90) {
19+
return true;
20+
}
21+
return false;
2922
};
3023

3124
const greaterThanFifty = (num) => {
32-
// return true if num is greater than fifty
33-
// otherwise return false
34-
// code here
25+
if (num > 50) {
26+
return true;
27+
}
28+
return false;
3529
};
3630

3731
const add = (x, y) => {
38-
// add x and y together and return the value
39-
// code here
32+
return x + y;
4033
};
4134

4235
const subtract = (x, y) => {
43-
// subtract y from x and return the value
44-
// code here
36+
return x - y;
4537
};
4638

4739
const divide = (x, y) => {
48-
// divide x by y and return the value
49-
// code here
40+
return x / y;
5041
};
5142

5243
const multiply = (x, y) => {
53-
// multiply x by y and return the value
54-
// code here
44+
return x * y;
5545
};
5646

5747
const getRemainder = (x, y) => {
58-
// return the remainder from dividing x by y
59-
// code here
48+
return x % y;
6049
};
6150

6251
const isEven = (num) => {
63-
// return true if num is even
64-
// otherwise return false
65-
// code here
52+
if (num % 2 === 0) {
53+
return true;
54+
}
55+
return false;
6656
};
6757

6858
const isOdd = (num) => {
69-
// return true if num is odd
70-
// otherwise return false
71-
// code here
59+
if (num % 2 === 0) {
60+
return false;
61+
}
62+
return true;
7263
};
7364

7465
const square = (num) => {
75-
// square num and return the new value
76-
// code here
66+
return num * num;
7767
};
7868

7969
const cube = (num) => {
80-
// cube num and return the new value
81-
// code here
70+
return num * num * num;
8271
};
8372

8473
const raiseToPower = (num, exponent) => {
85-
// raise num to whatever power is passed in as exponent
86-
// code here
74+
return num ** exponent;
8775
};
8876

8977
const roundNumber = (num) => {
90-
// round num and return it
91-
// code here
78+
return Math.round(num);
9279
};
9380

9481
const roundUp = (num) => {
95-
// round num up and return it
96-
// code here
82+
return Math.ceil(num);
9783
};
9884

9985
const addExclamationPoint = (str) => {
100-
// add an exclamation point to the end of str and return the new string
101-
// 'hello world' -> 'hello world!'
102-
// code here
86+
return (str += '!');
10387
};
10488

10589
const combineNames = (firstName, lastName) => {
106-
// return firstName and lastName combined as one string and separated by a space.
107-
// 'Lambda', 'School' -> 'Lambda School'
108-
// code here
90+
return `${firstName} ${lastName}`;
10991
};
11092

11193
const getGreeting = (name) => {
112-
// Take the name string and concatenate other strings onto it so it takes the following form:
113-
// 'Sam' -> 'Hello Sam!'
114-
// code here
94+
return `Hello ${name}!`;
11595
};
11696

117-
// If you can't remember these area formulas then head over to Google or look at the test code.
118-
11997
const getRectangleArea = (length, width) => {
120-
// return the area of the rectangle by using length and width
121-
// code here
98+
return length * width;
12299
};
123100

124101
const getTriangleArea = (base, height) => {
125-
// return the area of the triangle by using base and height
126-
// code here
102+
return 0.5 * base * height;
127103
};
128104

129105
const getCircleArea = (radius) => {
130-
// return the rounded area of the circle given the radius
131-
// code here
106+
return Math.round(radius * radius * Math.PI);
132107
};
133108

134109
const getRectangularPrismVolume = (length, width, height) => {
135-
// return the volume of the 3D rectangular prism given the length, width, and height
136-
// code here
110+
return width * height * length;
137111
};
138112

139-
// Do not modify code below this line.
140-
// --------------------------------
141-
142113
module.exports = {
143114
multiplyByTen,
144115
subtractFive,
Collapse file

‎src/project-2.js‎

Copy file name to clipboardExpand all lines: src/project-2.js
+97-53Lines changed: 97 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,110 +1,154 @@
1-
// Do not change any of the function names
2-
31
const getBiggest = (x, y) => {
4-
// x and y are integers. Return the larger integer
5-
// if they are the same return either one
2+
if (x > y) {
3+
return x;
4+
} else if (x === y) {
5+
return y;
6+
}
7+
return y;
68
};
79

810
const greeting = (language) => {
9-
// return a greeting for three different languages:
10-
// language: 'German' -> 'Guten Tag!'
11-
// language: 'Spanish' -> 'Hola!'
12-
// language: 'Chinese' -> 'Ni Hao!'
13-
// if language is undefined return 'Hello!'
11+
switch (language) {
12+
case 'German':
13+
return 'Guten Tag!';
14+
case 'Spanish':
15+
return 'Hola!';
16+
case 'Chinese':
17+
return 'Ni Hao!';
18+
default:
19+
return 'Hello!';
20+
}
1421
};
1522

1623
const isTenOrFive = (num) => {
17-
// return true if num is 10 or 5
18-
// otherwise return false
24+
if (num === 10 || num === 5) {
25+
return true;
26+
}
27+
return false;
1928
};
2029

2130
const isInRange = (num) => {
22-
// return true if num is less than 50 and greater than 20
31+
if (num < 50 && num > 20) {
32+
return true;
33+
}
34+
return false;
2335
};
2436

2537
const isInteger = (num) => {
26-
// return true if num is an integer
27-
// 0.8 -> false
28-
// 1 -> true
29-
// -10 -> true
30-
// otherwise return false
31-
// hint: you can solve this using Math.floor
38+
if (Math.floor(num) === num) {
39+
return true;
40+
}
41+
return false;
3242
};
3343

3444
const fizzBuzz = (num) => {
35-
// if num is divisible by 3 return 'fizz'
36-
// if num is divisible by 5 return 'buzz'
37-
// if num is divisible by 3 & 5 return 'fizzbuzz'
38-
// otherwise return num
45+
if (num % 5 === 0 && num % 3 === 0) {
46+
return 'fizzbuzz';
47+
} else if (num % 5 === 0) {
48+
return 'buzz';
49+
} else if (num % 3 === 0) {
50+
return 'fizz';
51+
}
52+
return num;
3953
};
4054

4155
const isPrime = (num) => {
42-
// return true if num is prime.
43-
// otherwise return false
44-
// hint: a prime number is only evenly divisible by itself and 1
45-
// hint2: you can solve this using a for loop
46-
// note: 0 and 1 are NOT considered prime numbers
56+
if (num < 0) {
57+
return false;
58+
}
59+
if (num === 1 || num === 0) {
60+
return false;
61+
}
62+
for (let i = 2; i < num; i++) {
63+
if (num % i === 0) {
64+
return false;
65+
}
66+
}
67+
return true;
4768
};
4869

4970
const returnFirst = (arr) => {
50-
// return the first item from the array
71+
return arr[0];
5172
};
5273

5374
const returnLast = (arr) => {
54-
// return the last item of the array
75+
return arr[arr.length - 1];
5576
};
5677

5778
const getArrayLength = (arr) => {
58-
// return the length of the array
79+
return arr.length;
5980
};
6081

6182
const incrementByOne = (arr) => {
62-
// arr is an array of integers
63-
// increase each integer by one
64-
// return the array
83+
for (let i = 0; i < arr.length; i++) {
84+
arr[i]++;
85+
}
86+
return arr;
6587
};
6688

6789
const addItemToArray = (arr, item) => {
68-
// add the item to the end of the array
69-
// return the array
90+
arr.push(item);
91+
return arr;
7092
};
7193

7294
const addItemToFront = (arr, item) => {
73-
// add the item to the front of the array
74-
// return the array
75-
// hint: use the array method .unshift
95+
arr.unshift(item);
96+
return arr;
7697
};
7798

7899
const wordsToSentence = (words) => {
79-
// words is an array of strings
80-
// return a string that is all of the words concatenated together
81-
// spaces need to be between each word
82-
// example: ['Hello', 'world!'] -> 'Hello world!'
100+
let newSentence = '';
101+
for (let i = 0; i < words.length; i++) {
102+
if (i === 0) {
103+
newSentence += `${words[i]}`;
104+
} else {
105+
newSentence += ` ${words[i]}`;
106+
}
107+
}
108+
return newSentence;
83109
};
84110

85111
const contains = (arr, item) => {
86-
// check to see if item is inside of arr
87-
// return true if it is, otherwise return false
112+
let itemCounter = 0;
113+
for (let i = 0; i < arr.length; i++) {
114+
if (arr[i] === item) {
115+
itemCounter++;
116+
}
117+
}
118+
if (itemCounter > 0) {
119+
return true;
120+
}
121+
return false;
88122
};
89123

90124
const addNumbers = (numbers) => {
91-
// numbers is an array of integers.
92-
// add all of the integers and return the value
125+
let sumOfNumbers = 0;
126+
for (let i = 0; i < numbers.length; i++) {
127+
sumOfNumbers += numbers[i];
128+
}
129+
return sumOfNumbers;
93130
};
94131

95132
const averageTestScore = (testScores) => {
96-
// testScores is an array. Iterate over testScores and compute the average.
97-
// return the average
133+
let totalSumScores = 0;
134+
let numberOfScore = 0;
135+
for (let i = 0; i < testScores.length; i++) {
136+
totalSumScores += testScores[i];
137+
numberOfScore++;
138+
}
139+
return totalSumScores / numberOfScore;
98140
};
99141

100142
const largestNumber = (numbers) => {
101-
// numbers is an array of integers
102-
// return the largest integer
143+
let biggestInteger = 0;
144+
for (let i = 0; i < numbers.length; i++) {
145+
if (numbers[i] > biggestInteger) {
146+
biggestInteger = numbers[i];
147+
}
148+
}
149+
return biggestInteger;
103150
};
104151

105-
// Do not modify code below this line.
106-
// --------------------------------
107-
108152
module.exports = {
109153
getBiggest,
110154
greeting,

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.